From b0d1e68dd445fccc7f0804cef11c3d305ffea366 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 8 Sep 2004 18:14:42 +0000 Subject: [PATCH] 2004-09-08 Dan Williams * panel-applet/no-networkmanager.png panel-applet/Makefile.am panel-applet/NMWirelessApplet.c - Add a "NetworkManager not running" icon and use it - Use new consolidated GConf keys rather than Preferred/Trusted * TODO: update * info-daemon/NetworkManagerInfo.c info-daemon/NetworkManagerInfoDbus.[ch] info-daemon/NetworkManagerInfoPassphraseDialog.c - There are now no longer two separate lists of wireless networks, but one list where each network is "trusted" or not trusted - Add a "getNetworkTrusted" dbus method - "WirelessNetworkUpdate" signal now sent rather than "PreferredNetworkUpdate/TrustedNetworkUpdate" signals - Start freeing some dbus errors (not completed yet) * info-daemon/passphrase.glade - Remove the "don't show" hints for pager and taskbar - Add a title since its going to be in the taskbar * src/NetworkManager.[ch] src/NetworkManagerAPList.[ch] - There are now no longer two separate lists of wireless networks, but one list where each network is "trusted" or not trusted * src/NetworkManagerAP.[ch] - Add get/set "trusted" accessors and data bit * src/NetworkManagerDbus.[ch] - Add function to get "trusted" status of a network from NetworkManagerInfo - Trap new WirelessNetworkUpdate signal rather than old separate signals * src/NetworkManagerDevice.[ch] - Add per-device config data (ip4 addr, gateway, netmask) and accessors - (nm_device_new): Get device config from backend when initializing devices - (nm_device_activation_worker): Split out device configuration on activation to deal with static/dynamic IP differences, and try encryption fallbacks on a device if the encryption method for the best AP is not good - (nm_device_update_best_ap): convert to new consolidated access point lists from NetworkManagerInfo, and copy over latest NMI info to best_ap when setting it * src/NetworkManagerWireless.c - libgcrypt code wasn't converting the MD5 digest to an ascii string, fix it * src/backends/NetworkManagerRedHat.c src/backends/NetworkManagerSystem.h - (nm_system_device_update_config_info): Add function to get device configuration from system data in ifcfg-* files * src/backends/NetworkManagerDebian.c src/backends/NetworkManagerGentoo.c src/backends/NetworkManagerSlackware.c - Add stub functions for getting device configuration git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@131 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 58 +++++ TODO | 23 +- info-daemon/NetworkManagerInfo.c | 23 +- info-daemon/NetworkManagerInfo.h | 3 +- info-daemon/NetworkManagerInfoDbus.c | 122 ++++----- info-daemon/NetworkManagerInfoDbus.h | 3 +- .../NetworkManagerInfoPassphraseDialog.c | 6 +- info-daemon/passphrase.glade | 4 +- panel-applet/Makefile.am | 30 +-- panel-applet/NMWirelessApplet.c | 40 +-- panel-applet/NMWirelessApplet.h | 1 + panel-applet/no-networkmanager.png | Bin 0 -> 2874 bytes src/NetworkManager.c | 14 +- src/NetworkManager.h | 3 +- src/NetworkManagerAP.c | 24 +- src/NetworkManagerAP.h | 59 ++--- src/NetworkManagerAPList.c | 6 +- src/NetworkManagerAPList.h | 3 +- src/NetworkManagerDbus.c | 67 ++++- src/NetworkManagerDbus.h | 2 + src/NetworkManagerDevice.c | 234 ++++++++++++------ src/NetworkManagerDevice.h | 11 + src/NetworkManagerPolicy.c | 16 +- src/NetworkManagerUtils.c | 1 + src/NetworkManagerWireless.c | 61 +++-- src/backends/NetworkManagerDebian.c | 11 + src/backends/NetworkManagerGentoo.c | 12 + src/backends/NetworkManagerRedHat.c | 100 ++++++++ src/backends/NetworkManagerSlackware.c | 13 + src/backends/NetworkManagerSystem.h | 2 + 30 files changed, 645 insertions(+), 307 deletions(-) create mode 100644 panel-applet/no-networkmanager.png diff --git a/ChangeLog b/ChangeLog index a4005feb2b..766e09e036 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,61 @@ +2004-09-08 Dan Williams + + * panel-applet/no-networkmanager.png + panel-applet/Makefile.am + panel-applet/NMWirelessApplet.c + - Add a "NetworkManager not running" icon and use it + - Use new consolidated GConf keys rather than Preferred/Trusted + + * TODO: update + + * info-daemon/NetworkManagerInfo.c + info-daemon/NetworkManagerInfoDbus.[ch] + info-daemon/NetworkManagerInfoPassphraseDialog.c + - There are now no longer two separate lists of wireless networks, + but one list where each network is "trusted" or not trusted + - Add a "getNetworkTrusted" dbus method + - "WirelessNetworkUpdate" signal now sent rather than + "PreferredNetworkUpdate/TrustedNetworkUpdate" signals + - Start freeing some dbus errors (not completed yet) + + * info-daemon/passphrase.glade + - Remove the "don't show" hints for pager and taskbar + - Add a title since its going to be in the taskbar + + * src/NetworkManager.[ch] + src/NetworkManagerAPList.[ch] + - There are now no longer two separate lists of wireless networks, + but one list where each network is "trusted" or not trusted + + * src/NetworkManagerAP.[ch] + - Add get/set "trusted" accessors and data bit + + * src/NetworkManagerDbus.[ch] + - Add function to get "trusted" status of a network from NetworkManagerInfo + - Trap new WirelessNetworkUpdate signal rather than old separate signals + + * src/NetworkManagerDevice.[ch] + - Add per-device config data (ip4 addr, gateway, netmask) and accessors + - (nm_device_new): Get device config from backend when initializing devices + - (nm_device_activation_worker): Split out device configuration on + activation to deal with static/dynamic IP differences, and try encryption + fallbacks on a device if the encryption method for the best AP is not good + - (nm_device_update_best_ap): convert to new consolidated access point lists from + NetworkManagerInfo, and copy over latest NMI info to best_ap when setting it + + * src/NetworkManagerWireless.c + - libgcrypt code wasn't converting the MD5 digest to an ascii string, fix it + + * src/backends/NetworkManagerRedHat.c + src/backends/NetworkManagerSystem.h + - (nm_system_device_update_config_info): Add function to get device configuration + from system data in ifcfg-* files + + * src/backends/NetworkManagerDebian.c + src/backends/NetworkManagerGentoo.c + src/backends/NetworkManagerSlackware.c + - Add stub functions for getting device configuration + 2004-09-07 Dan Williams * src/backends/NetworkManagerRedhat.c diff --git a/TODO b/TODO index 51cf1c6587..b6249fd8d7 100644 --- a/TODO +++ b/TODO @@ -3,19 +3,9 @@ TODO items for NetworkManager Any of these items are of course fair game for anyone, patches are greatly welcome. It also serves as a "what still needs to be done" list. -- Honor "cancelled" Wireless Networks +- More robust diff-ing of Wireless Networks after scans -When a user cancels the request for a WEP key, NetworkManagerInfo returns "***cancelled***" as the WEP key, which we need to trap and honor. One method to do this could be to add a boolean value 'invalid' to NMAccessPoint, and upon a cancel message set 'invalid' to TRUE. NM would not attempt to associate with 'invalid' access points. The 'invalid' marker would be cleared when the AP it was for had any value changed in GConf, or when the AP it was for went out of range. This means more complicated logic in the wireless scanning, since we have to retain 'invalid' state across scans (the scanned AP list is destroyed every scan). - - -- Alert user of new Wireless Networks - -This would again require preserving some state across wireless scans. We may need to hold the last scan while doing another, and diff the two structures at the end. We should also send DBUS signals onto the bus when wireless networks appear/disappear from a device. This would allow the UI portion (NetworkManagerInfo) to pop up some notification, and possibly ask the user whether he/she wants to add new wireless networks to the "allowed network" list - - -- Allow user-chosen Wireless Networks - -If the user decides to associate with one particular wireless network, via a wireless network applet or something, we need to temporarily suspend device switching until that wireless network drops out. One way to do this might be a boolean value in the NMData structure that stops device switching, which would be cleared when the wireless network that the active_device is associated with disappears. +Currently, after each scan the list of access points is diffed against the previous list. However, cards may not return the exact same list of access points for two different scans, depending on whether the card has detected traffic from that AP during the second scan or not. Therefore, we should probably keep a moving list of the past 3 scans, and diff the earliest two against the latest two to get a more stable list of access points. - Access Point link checking thresholds @@ -23,9 +13,9 @@ If the user decides to associate with one particular wireless network, via a wir Wireless link checking could be enhanced to check the signal strength of an access point and switch of the current access point a wireless card is associated with has dropped below say, 20%. -- Gracefully recover from dbus/hal and NetworkManagerInfo dropouts +- Gracefully recover from dbus and hal dropouts -There is currently no logic to gracefully recover from a crashed/killed dbus or hal. While we don't depend as heavily on NetworkManagerInfo, we need to make sure that we can operate effectively when it's not there. There are dbus functions for notification when services come up and go away which could be used here. Remeber that when dbus dies, hal also dies at the moment. +There is currently no logic to gracefully recover from a crashed/killed dbus or hal. There are dbus functions for notification when services come up and go away which could be used here. Remeber that when dbus dies, hal also dies at the moment. - Deal with blank ESSIDs @@ -33,11 +23,6 @@ There is currently no logic to gracefully recover from a crashed/killed dbus or Access points can be set not to broadcast their ESSIDs, which the client must know. These appear as blank ESSIDs to cards doing wireless scanning, even though the rest of the AP's information is known (channel, rate, etc). There has to be a way to deal with this as many companies do not broadcast ESSIDs for security measures. Workarounds for this practice could include brute-forcing the Allowed Networks list if no suitable wireless network is found to begin with. Obviously, there would be no way to detect if a WEP key was wrong, because unless the ESSID and WEP key are both correct, we cannot associate with the access point to see if we have a link. Code exists to do this for wireless cards that do not support wireless scanning, and this code could be adapted. -- Shorten standoff time between Pending and Active device promotion - -Currently, there is a 2 second wait between when a device is set as the Pending device, to when it may be promoted to Active device. 2 seconds is not technically necessary, the only reason to wait is that the GLib main loop must run at least once to deliver and receive queued up messages. This wait is also only necessary for wireless cards, where we may need to request a key from the user. This wait should be eliminated without breaking the Pending/Active device mechanism. - - - Support static IP addresses We need to support static IP addresses for interfaces. This should be done by parsing the normal /etc/sysconfig/network-scripts/ifcfg-* files. diff --git a/info-daemon/NetworkManagerInfo.c b/info-daemon/NetworkManagerInfo.c index 8ee73498e3..efd1e05a76 100644 --- a/info-daemon/NetworkManagerInfo.c +++ b/info-daemon/NetworkManagerInfo.c @@ -57,26 +57,11 @@ void nmi_gconf_notify_callback (GConfClient *client, guint connection_id, GConfE if ((key = gconf_entry_get_key (entry))) { - NMINetworkType type = NETWORK_TYPE_UNKNOWN; - int trusted_path_len = strlen (NMI_GCONF_TRUSTED_NETWORKS_PATH) + 1; - int preferred_path_len = strlen (NMI_GCONF_PREFERRED_NETWORKS_PATH) + 1; - int len; + int path_len = strlen (NMI_GCONF_WIRELESS_NETWORKS_PATH) + 1; - /* Extract the network name from the key */ - if (strncmp (NMI_GCONF_TRUSTED_NETWORKS_PATH"/", key, trusted_path_len) == 0) + if (strncmp (NMI_GCONF_WIRELESS_NETWORKS_PATH"/", key, path_len) == 0) { - type = NETWORK_TYPE_TRUSTED; - len = trusted_path_len; - } - else if (strncmp (NMI_GCONF_PREFERRED_NETWORKS_PATH"/", key, preferred_path_len) == 0) - { - type = NETWORK_TYPE_PREFERRED; - len = preferred_path_len; - } - - if (type != NETWORK_TYPE_UNKNOWN) - { - char *network = g_strdup ((key + len)); + char *network = g_strdup ((key + path_len)); char *slash_pos; /* If its a key under the network name, zero out the slash so we @@ -85,7 +70,7 @@ void nmi_gconf_notify_callback (GConfClient *client, guint connection_id, GConfE if ((slash_pos = strchr (network, '/'))) *slash_pos = '\0'; - nmi_dbus_signal_update_network (info->connection, network, type); + nmi_dbus_signal_update_network (info->connection, network, NETWORK_TYPE_ALLOWED); g_free (network); } } diff --git a/info-daemon/NetworkManagerInfo.h b/info-daemon/NetworkManagerInfo.h index 20d7a153a1..29c46ab4d1 100644 --- a/info-daemon/NetworkManagerInfo.h +++ b/info-daemon/NetworkManagerInfo.h @@ -46,7 +46,6 @@ struct NMIAppInfo typedef struct NMIAppInfo NMIAppInfo; #define NMI_GCONF_WIRELESS_NETWORKING_PATH "/system/networking/wireless" -#define NMI_GCONF_TRUSTED_NETWORKS_PATH "/system/networking/wireless/trusted_networks" -#define NMI_GCONF_PREFERRED_NETWORKS_PATH "/system/networking/wireless/preferred_networks" +#define NMI_GCONF_WIRELESS_NETWORKS_PATH "/system/networking/wireless/networks" #endif diff --git a/info-daemon/NetworkManagerInfoDbus.c b/info-daemon/NetworkManagerInfoDbus.c index 0105429f01..a9ab7e624e 100644 --- a/info-daemon/NetworkManagerInfoDbus.c +++ b/info-daemon/NetworkManagerInfoDbus.c @@ -50,9 +50,7 @@ */ inline gboolean nmi_network_type_valid (NMINetworkType type) { - if ((type == NETWORK_TYPE_TRUSTED) || (type == NETWORK_TYPE_PREFERRED)) - return (TRUE); - return (FALSE); + return ((type == NETWORK_TYPE_ALLOWED)); } @@ -155,21 +153,14 @@ void nmi_dbus_return_user_key (DBusConnection *connection, const char *device, void nmi_dbus_signal_update_network (DBusConnection *connection, const char *network, NMINetworkType type) { DBusMessage *message; - const char *trusted_signal = "TrustedNetworkUpdate"; - const char *preferred_signal = "PreferredNetworkUpdate"; - const char *signal; g_return_if_fail (connection != NULL); g_return_if_fail (network != NULL); - switch (type) - { - case (NETWORK_TYPE_TRUSTED): signal = trusted_signal; break; - case (NETWORK_TYPE_PREFERRED): signal = preferred_signal; break; - default: return; - } + if (type != NETWORK_TYPE_ALLOWED) + return; - message = dbus_message_new_signal (NMI_DBUS_PATH, NMI_DBUS_INTERFACE, signal); + message = dbus_message_new_signal (NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "WirelessNetworkUpdate"); if (!message) { syslog (LOG_ERR, "nmi_dbus_signal_update_network(): Not enough memory for new dbus message!"); @@ -178,7 +169,7 @@ void nmi_dbus_signal_update_network (DBusConnection *connection, const char *net dbus_message_append_args (message, DBUS_TYPE_STRING, network, DBUS_TYPE_INVALID); if (!dbus_connection_send (connection, message, NULL)) - syslog (LOG_WARNING, "nmi_dbus_signal_update_network(): Could not raise the '%s' signal!", signal); + syslog (LOG_WARNING, "nmi_dbus_signal_update_network(): Could not raise the 'WirelessNetworkUpdate' signal!"); dbus_message_unref (message); } @@ -199,7 +190,6 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag DBusMessage *reply_message = NULL; DBusMessageIter iter; DBusMessageIter iter_array; - const char *path; NMINetworkType type; g_return_val_if_fail (info != NULL, NULL); @@ -220,21 +210,12 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag return (reply_message); } - switch (type) - { - case (NETWORK_TYPE_TRUSTED): path = NMI_GCONF_TRUSTED_NETWORKS_PATH; break; - case (NETWORK_TYPE_PREFERRED): path = NMI_GCONF_PREFERRED_NETWORKS_PATH; break; - default: return (NULL); /* shouldn't get here */ - } - /* List all allowed access points that gconf knows about */ - element = dir_list = gconf_client_all_dirs (info->gconf_client, path, NULL); - + element = dir_list = gconf_client_all_dirs (info->gconf_client, NMI_GCONF_WIRELESS_NETWORKS_PATH, NULL); if (!dir_list) { reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoNetworks", - "There were are no %s networks stored.", - type == NETWORK_TYPE_TRUSTED ? "trusted" : (type == NETWORK_TYPE_PREFERRED ? "preferred" : "unknown")); + "There were are no wireless networks stored."); } else { @@ -271,8 +252,7 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag { dbus_message_unref (reply_message); reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoNetworks", - "There were are no %s networks stored.", - type == NETWORK_TYPE_TRUSTED ? "trusted" : (type == NETWORK_TYPE_PREFERRED ? "preferred" : "unknown")); + "There were are no wireless networks stored."); } } @@ -294,7 +274,6 @@ static DBusMessage *nmi_dbus_get_network_timestamp (NMIAppInfo *info, DBusMessag char *network = NULL; GConfValue *value; DBusError error; - const char *path; NMINetworkType type; g_return_val_if_fail (info != NULL, NULL); @@ -310,15 +289,8 @@ static DBusMessage *nmi_dbus_get_network_timestamp (NMIAppInfo *info, DBusMessag return (reply_message); } - switch (type) - { - case (NETWORK_TYPE_TRUSTED): path = NMI_GCONF_TRUSTED_NETWORKS_PATH; break; - case (NETWORK_TYPE_PREFERRED): path = NMI_GCONF_PREFERRED_NETWORKS_PATH; break; - default: return (NULL); - } - /* Grab timestamp key for our access point from GConf */ - key = g_strdup_printf ("%s/%s/timestamp", path, network); + key = g_strdup_printf ("%s/%s/timestamp", NMI_GCONF_WIRELESS_NETWORKS_PATH, network); value = gconf_client_get (info->gconf_client, key, NULL); g_free (key); @@ -353,7 +325,6 @@ static DBusMessage *nmi_dbus_get_network_essid (NMIAppInfo *info, DBusMessage *m char *network = NULL; GConfValue *value; DBusError error; - const char *path; NMINetworkType type; g_return_val_if_fail (info != NULL, NULL); @@ -369,15 +340,8 @@ static DBusMessage *nmi_dbus_get_network_essid (NMIAppInfo *info, DBusMessage *m return (reply_message); } - switch (type) - { - case (NETWORK_TYPE_TRUSTED): path = NMI_GCONF_TRUSTED_NETWORKS_PATH; break; - case (NETWORK_TYPE_PREFERRED): path = NMI_GCONF_PREFERRED_NETWORKS_PATH; break; - default: return (NULL); - } - /* Grab essid key for our access point from GConf */ - key = g_strdup_printf ("%s/%s/essid", path, network); + key = g_strdup_printf ("%s/%s/essid", NMI_GCONF_WIRELESS_NETWORKS_PATH, network); value = gconf_client_get (info->gconf_client, key, NULL); g_free (key); @@ -412,7 +376,6 @@ static DBusMessage *nmi_dbus_get_network_key (NMIAppInfo *info, DBusMessage *mes char *network = NULL; GConfValue *value; DBusError error; - const char *path; NMINetworkType type; g_return_val_if_fail (info != NULL, NULL); @@ -428,15 +391,8 @@ static DBusMessage *nmi_dbus_get_network_key (NMIAppInfo *info, DBusMessage *mes return (reply_message); } - switch (type) - { - case (NETWORK_TYPE_TRUSTED): path = NMI_GCONF_TRUSTED_NETWORKS_PATH; break; - case (NETWORK_TYPE_PREFERRED): path = NMI_GCONF_PREFERRED_NETWORKS_PATH; break; - default: return (NULL); - } - /* Grab user-key key for our access point from GConf */ - key = g_strdup_printf ("%s/%s/key", path, network); + key = g_strdup_printf ("%s/%s/key", NMI_GCONF_WIRELESS_NETWORKS_PATH, network); value = gconf_client_get (info->gconf_client, key, NULL); g_free (key); @@ -454,6 +410,54 @@ static DBusMessage *nmi_dbus_get_network_key (NMIAppInfo *info, DBusMessage *mes } +/* + * nmi_dbus_get_network_trusted + * + * If the specified network exists, get its "trusted" value + * from gconf and pass it back. + * + */ +static DBusMessage *nmi_dbus_get_network_trusted (NMIAppInfo *info, DBusMessage *message) +{ + DBusMessage *reply_message = NULL; + gchar *key = NULL; + char *network = NULL; + GConfValue *value; + DBusError error; + NMINetworkType type; + + g_return_val_if_fail (info != 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, &type, DBUS_TYPE_INVALID) + || !nmi_network_type_valid (type) + || (strlen (network) <= 0)) + { + reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", + "NetworkManagerInfo::getNetworkTrusted called with invalid arguments."); + return (reply_message); + } + + /* Grab user-key key for our access point from GConf */ + key = g_strdup_printf ("%s/%s/trusted", NMI_GCONF_WIRELESS_NETWORKS_PATH, network); + value = gconf_client_get (info->gconf_client, key, NULL); + g_free (key); + + /* We don't error out if no key was found in gconf, we return blank key */ + reply_message = dbus_message_new_method_return (message); + if (value) + { + dbus_message_append_args (reply_message, DBUS_TYPE_BOOLEAN, gconf_value_get_bool (value), DBUS_TYPE_INVALID); + gconf_value_free (value); + } + else + dbus_message_append_args (reply_message, DBUS_TYPE_BOOLEAN, FALSE, DBUS_TYPE_INVALID); + + return (reply_message); +} + + /* * nmi_dbus_nmi_message_handler * @@ -472,7 +476,7 @@ static DBusHandlerResult nmi_dbus_nmi_message_handler (DBusConnection *connectio method = dbus_message_get_member (message); path = dbus_message_get_path (message); - /* syslog (LOG_DEBUG, "nmi_dbus_nmi_message_handler() got method %s for path %s", method, path); */ + syslog (LOG_WARNING, "nmi_dbus_nmi_message_handler() got method %s for path %s", method, path); if (strcmp ("getKeyForNetwork", method) == 0) { @@ -494,6 +498,8 @@ static DBusHandlerResult nmi_dbus_nmi_message_handler (DBusConnection *connectio reply_message = nmi_dbus_get_network_essid (info, message); else if (strcmp ("getNetworkKey", method) == 0) reply_message = nmi_dbus_get_network_key (info, message); + else if (strcmp ("getNetworkTrusted", method) == 0) + reply_message = nmi_dbus_get_network_trusted (info, message); else { reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "UnknownMethod", @@ -581,6 +587,7 @@ int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info) if (dbus_error_is_set (&dbus_error)) { syslog (LOG_ERR, "nmi_dbus_service_init() could not acquire its service. dbus_bus_acquire_service() says: '%s'", dbus_error.message); + dbus_error_free (&dbus_error); return (-1); } @@ -600,7 +607,10 @@ int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info) "sender='" NM_DBUS_SERVICE "'," "path='" NM_DBUS_PATH "'", &dbus_error); if (dbus_error_is_set (&dbus_error)) + { + dbus_error_free (&dbus_error); return (-1); + } return (0); } diff --git a/info-daemon/NetworkManagerInfoDbus.h b/info-daemon/NetworkManagerInfoDbus.h index ecdffd966d..3c0206a29c 100644 --- a/info-daemon/NetworkManagerInfoDbus.h +++ b/info-daemon/NetworkManagerInfoDbus.h @@ -32,8 +32,7 @@ typedef enum { NETWORK_TYPE_UNKNOWN = 0, - NETWORK_TYPE_TRUSTED, - NETWORK_TYPE_PREFERRED, + NETWORK_TYPE_ALLOWED, NETWORK_TYPE_INVALID, NETWORK_TYPE_DEVICE } NMINetworkType; diff --git a/info-daemon/NetworkManagerInfoPassphraseDialog.c b/info-daemon/NetworkManagerInfoPassphraseDialog.c index 44ceb1dcb7..1ee3495464 100644 --- a/info-daemon/NetworkManagerInfoPassphraseDialog.c +++ b/info-daemon/NetworkManagerInfoPassphraseDialog.c @@ -92,16 +92,16 @@ void nmi_passphrase_dialog_ok_clicked (GtkWidget *ok_button, gpointer user_data) nmi_dbus_return_user_key (info->connection, device, network, passphrase); /* Update GConf with the new user key */ - key = g_strdup_printf ("%s/%s", NMI_GCONF_TRUSTED_NETWORKS_PATH, network); + key = g_strdup_printf ("%s/%s", NMI_GCONF_WIRELESS_NETWORKS_PATH, network); gconf_entry = gconf_client_get_entry (info->gconf_client, key, NULL, TRUE, NULL); g_free (key); if (gconf_entry) { gconf_entry_unref (gconf_entry); - key = g_strdup_printf ("%s/%s/key", NMI_GCONF_TRUSTED_NETWORKS_PATH, network); + key = g_strdup_printf ("%s/%s/key", NMI_GCONF_WIRELESS_NETWORKS_PATH, network); gconf_client_set_string (info->gconf_client, key, passphrase, NULL); g_free (key); - key = g_strdup_printf ("%s/%s/essid", NMI_GCONF_TRUSTED_NETWORKS_PATH, network); + key = g_strdup_printf ("%s/%s/essid", NMI_GCONF_WIRELESS_NETWORKS_PATH, network); gconf_client_set_string (info->gconf_client, key, network, NULL); g_free (key); } diff --git a/info-daemon/passphrase.glade b/info-daemon/passphrase.glade index b4d19f77ce..8cc1fe6742 100644 --- a/info-daemon/passphrase.glade +++ b/info-daemon/passphrase.glade @@ -6,15 +6,13 @@ 6 True - + Wireless Network Key Required GTK_WINDOW_TOPLEVEL GTK_WIN_POS_CENTER_ALWAYS False False False True - True - True GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST False diff --git a/panel-applet/Makefile.am b/panel-applet/Makefile.am index 0b33be9b00..9a38c7da8c 100644 --- a/panel-applet/Makefile.am +++ b/panel-applet/Makefile.am @@ -44,20 +44,22 @@ gladedir = $(datadir)/NMWirelessApplet glade_DATA = wireless-applet.glade pixmapdir = $(datadir)/pixmaps/NMWirelessApplet -pixmap_DATA = no-link-0.png \ - wired.png \ - wireless.png \ - broken-0.png \ - signal-1-40.png \ - signal-41-60.png \ - signal-61-80.png \ - signal-81-100.png \ - wireless-applet.png \ - connect-0.png \ - connect-1.png \ - connect-2.png \ - connect-3.png \ - keyring.png \ +pixmap_DATA = \ + no-networkmanager.png \ + no-link-0.png \ + wired.png \ + wireless.png \ + broken-0.png \ + signal-1-40.png \ + signal-41-60.png \ + signal-61-80.png \ + signal-81-100.png \ + wireless-applet.png \ + connect-0.png \ + connect-1.png \ + connect-2.png \ + connect-3.png \ + keyring.png \ $(NULL) CLEANFILES = $(server_DATA) *.bak *.gladep diff --git a/panel-applet/NMWirelessApplet.c b/panel-applet/NMWirelessApplet.c index 6daaaa1b5a..f555302772 100644 --- a/panel-applet/NMWirelessApplet.c +++ b/panel-applet/NMWirelessApplet.c @@ -47,11 +47,11 @@ #include "NMWirelessAppletDbus.h" #define CFG_UPDATE_INTERVAL 1 -#define NM_GCONF_TRUSTED_NETWORKS_PATH "/system/networking/wireless/trusted_networks" -#define NM_GCONF_PREFERRED_NETWORKS_PATH "/system/networking/wireless/preferred_networks" +#define NM_GCONF_WIRELESS_NETWORKS_PATH "/system/networking/wireless/networks" static char * pixmap_names[] = { + "no-networkmanager.png", "wired.png", "no-link-0.png", "signal-1-40.png", @@ -127,7 +127,7 @@ static void nmwa_update_state (NMWirelessApplet *applet) switch (applet->applet_state) { case (APPLET_STATE_NO_NM): - applet->pix_state = PIX_WIRED; /* FIXME: get a "no NetworkManager" picture */ + applet->pix_state = PIX_NO_NETWORKMANAGER; break; case (APPLET_STATE_NO_CONNECTION): @@ -384,34 +384,16 @@ void nmwa_handle_network_choice (NMWirelessApplet *applet, char *network) /* Update GConf to set timestamp for this network, or add it if * it doesn't already exist. */ - key = g_strdup_printf ("%s/%s", NM_GCONF_TRUSTED_NETWORKS_PATH, network); - gconf_entry = gconf_client_get_entry (applet->gconf_client, key, NULL, TRUE, NULL); + + /* Update timestamp on network */ + key = g_strdup_printf ("%s/%s/timestamp", NM_GCONF_WIRELESS_NETWORKS_PATH, network); + gconf_client_set_int (applet->gconf_client, key, time (NULL), NULL); g_free (key); - if (gconf_entry) - { - /* Update timestamp on existing network in trusted networks */ - key = g_strdup_printf ("%s/%s/timestamp", NM_GCONF_TRUSTED_NETWORKS_PATH, network); - gconf_client_set_int (applet->gconf_client, key, time (NULL), NULL); - g_free (key); - - /* Force-set the essid too so that we have a semi-complete network entry */ - key = g_strdup_printf ("%s/%s/essid", NM_GCONF_TRUSTED_NETWORKS_PATH, network); - gconf_client_set_string (applet->gconf_client, key, network, NULL); - g_free (key); - } - else - { - /* If its not already in trusted networks, add the chosen network to preferred networks */ - key = g_strdup_printf ("%s/%s/timestamp", NM_GCONF_PREFERRED_NETWORKS_PATH, network); - gconf_client_set_int (applet->gconf_client, key, time (NULL), NULL); - g_free (key); - - /* Force-set the essid too so that we have a semi-complete network entry */ - key = g_strdup_printf ("%s/%s/essid", NM_GCONF_PREFERRED_NETWORKS_PATH, network); - gconf_client_set_string (applet->gconf_client, key, network, NULL); - g_free (key); - } + /* Force-set the essid too so that we have a semi-complete network entry */ + key = g_strdup_printf ("%s/%s/essid", NM_GCONF_WIRELESS_NETWORKS_PATH, network); + gconf_client_set_string (applet->gconf_client, key, network, NULL); + g_free (key); fprintf (stderr, "Forcing network '%s'\n", network); nmwa_dbus_set_network (applet->connection, network); diff --git a/panel-applet/NMWirelessApplet.h b/panel-applet/NMWirelessApplet.h index db7d72469e..0f9d063baa 100644 --- a/panel-applet/NMWirelessApplet.h +++ b/panel-applet/NMWirelessApplet.h @@ -32,6 +32,7 @@ typedef enum { + PIX_NO_NETWORKMANAGER, PIX_WIRED, PIX_WIRELESS_NO_LINK, PIX_WIRELESS_SIGNAL_1, diff --git a/panel-applet/no-networkmanager.png b/panel-applet/no-networkmanager.png new file mode 100644 index 0000000000000000000000000000000000000000..e51c32c07b9594fdd9f4a04b9c979262e410ea3e GIT binary patch literal 2874 zcmV-A3&r$_P)1uigH@BI2n8ZZfRLrxGg&7y^WMGvW8O?A5ts?0@<-n}_snl* z?z`{%z3+E_EBycZaWBOqNRU21DpwIcg>U1LKEn;Z^SBDY-<^?>(HWCx+zW&QmJ5Qv z3Wz9)iHR4)larI2Mc^bG5h*1Ms?T02I!SFL>8_*26lt2OgPzO6e zEZqS+;841FqjD91*L~HN(vCc)wdsHX^m<|Z@ zAv&NdfvJFQg3$pN;53H=Xf@4Un>k#x&%flAm6`d^?KwFCtI*7cpP06I>LXJqJerSz zq<^<4nj^wl)#l`(v2y|;!nQBp;AlZPF(DdJs_Nc0A&@GxHn)KSvmSaeAhj8AL-LFZ z1)Ucou=v(VH*5(VZ^JBSPsDAI;arl{7B>BXeiJ=J%mL&-gtbJUW$ODLvU) zP=e3}5{aU!qz&lJlaDVC2>g`kne(ENe0B!H5JbjAAf-f6K-U9Oc_uwD9^rIh7=}N?(9w+A>Y8Y6X+=nh zlu%V(!^)RFKuF1|mp?>EK}~gaKp;L@{uwTpi~4FCPKN`B!^zW6t@L}}*vaWQ9S(Gt z6T=X`fBgv<1_X6B{oXIVLfr;KN=Z$5jhmFshLqC#dGzQ}CjRCFfUGRPf{zPtaXU!R6FxYjc8ZC$Mwp&J1845Mz>1zC}P)6spQpIcV(Tp595-BCywrwLbGZQH#`KL}XWa!Y#20w1fC@?zu zsMf|d4B7Dj8-`)=dx!_cM) zhGDR7-8!CKxbU*Tk4jGm2?9a0GnNyTBWP%gLr8%XAcgQ%u@--xn8JEH3BBXFcXl>& z7yXXx>};G)Cw9A?!-o$egkbdO(b(;F>~=ds2<&z{4u^xU^YXd`{@>||L=+yw<#YiM zR$4%xmCq7Ucnn2R!1NtnCn=@nV&O!)K1o4!c`d76{t%nZ#_H9p2@4COrKN@Z{CrNF zIDxL~-oy3oyYHgwI=Zg2Y}qpOnKN1b_S;<|;&iwO(?UAAbZM4JMAxFxf$>osvOBr^ zzKKM~M{(2OvE=3D(bUw0loBBXLI@1QKnP(vD8)<2x?@Mc!0-5~f<-sp2($nSjy{8_ zn*9Ryx86cZ8xlJB0Zr2!W?*=66)LE0A|g7Rknj*HN~_tla~;#BO{2+67z%?Q`HP>>{FTepPbGsRSw*HBm6Ky^tq zEzPYo)HZ`6aXEB^5U8pOQsQ#DsH<+gA}QtA$!XM9+Ndb5rr%GJF?7MuAwzlK7qiI9 z$^y6(_^&zY&2U|IOesC)3x&w2aH8X*xP8oUqGBVMG+`u>G2vuS97Sk&Fq5-J1_VBJ zP!c0D2K$}2d*dOxB}6gf!7LPuN^oe9uOGwAC2T;WnN!FM=fs{Wk)jaUErO`nNKytQ z5tk54a{naadc@GXUm~&HWBh{3xcz#P2lk>{LJSL@xzF$XFE$+o)eT5dWT$!whPms8 ziBk2T^;#iANE8)*nwp49cVRdU_MJQnio*U==eT8ffA${4xKK;<#b@^rpXin zAtk#v9`p-h%%n7KQ4|j3pCc$(L$#<_EGknT9?ymqxqk0|dcgwjm^hJ?loao8n>TMJ zK0Y2z(>QbH4ENk~Ppv2L^=^$K6+j>i!R%i?%B)FK85S2t`k)l%&wh>Zq@;XVIcXtXZ=LpvFr;2p!#! z2q|c@9mm!9AO8O4R(2mg&21AV1YAo=ADqG$c?DimsF)#G&u&pvH8hbu^ERf;81Hwj zWy^iiPfIYG)*dt@BqR_Q7e`J`PWvI2C?F&VN#2pqneyOL04mN`b*a^(J9V$hNddyA zHF3V$=6%}a>Eryandvs6=!6gy6y*JV)-11iZ9l|Kwq{hf381D$Vb*W ?=^@_nn{ z2Ti|!0uLAhMOD#)G;Y4GA0eT^Xh9Y%ngvyHb4VMI!dC^w2oZSMOajXr8)&PB|We%!gL*4R)`e414fLl;z*)lzxBmga_5Mq~`++O*U_NbCX%fU`g~(C9e> zZ!CRgRXFh2q5#0Z{`zdRBl%3YVK7Jt3euQxy*p&EXcjWBAL0!K#*Y|;qPP$9sDXWn z3JXD+Br48TQ&m>qK~1E85*3P1&DBGo4p<`LF@NAUemtL4K-Day_Kb6@pQezS80WS7 z9vPr-LYx_DNrt8NLQ32fJ41NDF9Z&lk)||B?DW?|Q#yqbx`Z0PCBGS&yqem}TLu_r z%2L4aYkGUqKd&r=XqOGa@P5f&SxE0*@Aru^b+a;_BHcRfznzJn^0ntWd*DqBpYovY zGJLBB?Xuo3yPUpr+A}Oe2rQb{emG3<)#j)Issrs|X@N}o*N1;bDJsR~G{`F|H3{f$ zS%R(`Yv=oFtxB``;ZYsCk1DHu`}TdfxVU&Z@E6>T?K7sa=}@lt YA1MKVWh#=L`v3p{07*qoM6N<$g0TW@JOBUy literal 0 HcmV?d00001 diff --git a/src/NetworkManager.c b/src/NetworkManager.c index 4bc06c60bf..f11924d5ea 100644 --- a/src/NetworkManager.c +++ b/src/NetworkManager.c @@ -45,7 +45,6 @@ /* * Globals */ -static GMainLoop *loop = NULL; static NMData *nm_data = NULL; extern gboolean allowed_ap_worker_exit; @@ -439,19 +438,18 @@ static NMData *nm_data_new (gboolean enable_test_devices) if (!data->dev_list_mutex || !data->user_device_mutex || !data->state_modified_mutex) { nm_data_free (data); - syslog( LOG_ERR, "Could not initialize data structure locks."); + syslog (LOG_ERR, "Could not initialize data structure locks."); return (NULL); } /* Initialize the access point lists */ - data->trusted_ap_list = nm_ap_list_new (NETWORK_TYPE_TRUSTED); - data->preferred_ap_list = nm_ap_list_new (NETWORK_TYPE_PREFERRED); + data->allowed_ap_list = nm_ap_list_new (NETWORK_TYPE_ALLOWED); data->invalid_ap_list = nm_ap_list_new (NETWORK_TYPE_INVALID); - if (!data->trusted_ap_list || !data->preferred_ap_list || !data->invalid_ap_list) + if (!data->allowed_ap_list || !data->invalid_ap_list) { nm_data_free (data); - syslog( LOG_ERR, "Could not create access point lists. Whacky stuff going on?"); + syslog (LOG_ERR, "Could not create access point lists. Whacky stuff going on?"); return (NULL); } @@ -481,8 +479,7 @@ static void nm_data_free (NMData *data) g_mutex_free (data->user_device_mutex); g_mutex_free (data->state_modified_mutex); - nm_ap_list_unref (data->trusted_ap_list); - nm_ap_list_unref (data->preferred_ap_list); + nm_ap_list_unref (data->allowed_ap_list); nm_ap_list_unref (data->invalid_ap_list); memset (data, 0, sizeof (NMData)); @@ -540,6 +537,7 @@ int main( int argc, char *argv[] ) guint wireless_scan_source; gboolean become_daemon = TRUE; gboolean enable_test_devices = FALSE; + GMainLoop *loop = NULL; /* Parse options */ while (1) diff --git a/src/NetworkManager.h b/src/NetworkManager.h index 4f60ff5a0d..d63f8af44a 100644 --- a/src/NetworkManager.h +++ b/src/NetworkManager.h @@ -48,8 +48,7 @@ typedef struct NMData GMutex *state_modified_mutex; gboolean update_ap_lists; - struct NMAccessPointList *trusted_ap_list; - struct NMAccessPointList *preferred_ap_list; + struct NMAccessPointList *allowed_ap_list; struct NMAccessPointList *invalid_ap_list; } NMData; diff --git a/src/NetworkManagerAP.c b/src/NetworkManagerAP.c index 06cba0c38f..727d47a433 100644 --- a/src/NetworkManagerAP.c +++ b/src/NetworkManagerAP.c @@ -40,10 +40,11 @@ struct NMAccessPoint NMAPEncMethod enc_method; gboolean enc_method_good; gboolean matched; // used in ap list diffing + gboolean trusted; /* Things from user prefs */ gchar *enc_key; - GTimeVal timestamp; + GTimeVal timestamp; }; @@ -222,7 +223,6 @@ gchar *nm_ap_get_enc_key_hashed (NMAccessPoint *ap, NMAPEncMethod method) break; default: - hashed = NULL; break; } @@ -416,3 +416,23 @@ void nm_ap_set_enc_method_good (NMAccessPoint *ap, gboolean good) ap->enc_method_good = good; } + + +/* + * Get/Set functions to indicate that an access point is + * 'trusted' + * + */ +gboolean nm_ap_get_trusted (NMAccessPoint *ap) +{ + g_return_val_if_fail (ap != NULL, FALSE); + + return (ap->trusted); +} + +void nm_ap_set_trusted (NMAccessPoint *ap, gboolean trusted) +{ + g_return_if_fail (ap != NULL); + + ap->trusted = trusted; +} diff --git a/src/NetworkManagerAP.h b/src/NetworkManagerAP.h index 281535899b..d8a7a1209e 100644 --- a/src/NetworkManagerAP.h +++ b/src/NetworkManagerAP.h @@ -37,47 +37,50 @@ typedef enum NMAPEncMethod } NMAPEncMethod; -NMAccessPoint *nm_ap_new (void); -NMAccessPoint *nm_ap_new_from_ap (NMAccessPoint *ap); +NMAccessPoint * nm_ap_new (void); +NMAccessPoint * nm_ap_new_from_ap (NMAccessPoint *ap); -void nm_ap_unref (NMAccessPoint *ap); -void nm_ap_ref (NMAccessPoint *ap); +void nm_ap_unref (NMAccessPoint *ap); +void nm_ap_ref (NMAccessPoint *ap); const GTimeVal * nm_ap_get_timestamp (NMAccessPoint *ap); -void nm_ap_set_timestamp (NMAccessPoint *ap, const GTimeVal *timestamp); +void nm_ap_set_timestamp (NMAccessPoint *ap, const GTimeVal *timestamp); -gchar * nm_ap_get_essid (NMAccessPoint *ap); -void nm_ap_set_essid (NMAccessPoint *ap, gchar *essid); +gchar * nm_ap_get_essid (NMAccessPoint *ap); +void nm_ap_set_essid (NMAccessPoint *ap, gchar *essid); -gchar * nm_ap_get_enc_key_source (NMAccessPoint *ap); -gchar * nm_ap_get_enc_key_hashed (NMAccessPoint *ap, NMAPEncMethod method); -void nm_ap_set_enc_key_source (NMAccessPoint *ap, gchar *key); +gchar * nm_ap_get_enc_key_source (NMAccessPoint *ap); +gchar * nm_ap_get_enc_key_hashed (NMAccessPoint *ap, NMAPEncMethod method); +void nm_ap_set_enc_key_source (NMAccessPoint *ap, gchar *key); -gboolean nm_ap_get_encrypted (NMAccessPoint *ap); -void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean encrypted); +gboolean nm_ap_get_encrypted (NMAccessPoint *ap); +void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean encrypted); -struct ether_addr * nm_ap_get_address (NMAccessPoint *ap); -void nm_ap_set_address (NMAccessPoint *ap, const struct ether_addr *addr); +struct ether_addr * nm_ap_get_address (NMAccessPoint *ap); +void nm_ap_set_address (NMAccessPoint *ap, const struct ether_addr *addr); -guint8 nm_ap_get_quality (NMAccessPoint *ap); -void nm_ap_set_quality (NMAccessPoint *ap, guint8 quality); +guint8 nm_ap_get_quality (NMAccessPoint *ap); +void nm_ap_set_quality (NMAccessPoint *ap, guint8 quality); -double nm_ap_get_freq (NMAccessPoint *ap); -void nm_ap_set_freq (NMAccessPoint *ap, double freq); +double nm_ap_get_freq (NMAccessPoint *ap); +void nm_ap_set_freq (NMAccessPoint *ap, double freq); -guint16 nm_ap_get_rate (NMAccessPoint *ap); -void nm_ap_set_rate (NMAccessPoint *ap, guint16 rate); +guint16 nm_ap_get_rate (NMAccessPoint *ap); +void nm_ap_set_rate (NMAccessPoint *ap, guint16 rate); -gboolean nm_ap_get_invalid (NMAccessPoint *ap); -void nm_ap_set_invalid (NMAccessPoint *ap, gboolean invalid); +gboolean nm_ap_get_invalid (NMAccessPoint *ap); +void nm_ap_set_invalid (NMAccessPoint *ap, gboolean invalid); -gboolean nm_ap_get_matched (NMAccessPoint *ap); -void nm_ap_set_matched (NMAccessPoint *ap, gboolean matched); +gboolean nm_ap_get_matched (NMAccessPoint *ap); +void nm_ap_set_matched (NMAccessPoint *ap, gboolean matched); -NMAPEncMethod nm_ap_get_enc_method (NMAccessPoint *ap); -void nm_ap_set_enc_method (NMAccessPoint *ap, NMAPEncMethod enc_method); +NMAPEncMethod nm_ap_get_enc_method (NMAccessPoint *ap); +void nm_ap_set_enc_method (NMAccessPoint *ap, NMAPEncMethod enc_method); -gboolean nm_ap_get_enc_method_good (NMAccessPoint *ap); -void nm_ap_set_enc_method_good (NMAccessPoint *ap, gboolean good); +gboolean nm_ap_get_enc_method_good (NMAccessPoint *ap); +void nm_ap_set_enc_method_good (NMAccessPoint *ap, gboolean good); + +gboolean nm_ap_get_trusted (NMAccessPoint *ap); +void nm_ap_set_trusted (NMAccessPoint *ap, gboolean trusted); #endif diff --git a/src/NetworkManagerAPList.c b/src/NetworkManagerAPList.c index 68aa104fb7..6801d64e2c 100644 --- a/src/NetworkManagerAPList.c +++ b/src/NetworkManagerAPList.c @@ -226,13 +226,14 @@ void nm_ap_list_update_network (NMAccessPointList *list, const char *network, NM g_return_if_fail (list != NULL); g_return_if_fail (network != NULL); - g_return_if_fail (((list->type == NETWORK_TYPE_TRUSTED) || (list->type == NETWORK_TYPE_PREFERRED))); + g_return_if_fail (list->type == NETWORK_TYPE_ALLOWED); /* Get the allowed access point's details from NetworkManagerInfo */ if ((essid = nm_dbus_get_network_essid (data->dbus_connection, list->type, network))) { char *key = nm_dbus_get_network_key (data->dbus_connection, list->type, network); GTimeVal *timestamp = nm_dbus_get_network_timestamp (data->dbus_connection, list->type, network); + gboolean trusted = nm_dbus_get_network_trusted (data->dbus_connection, list->type, network); if (timestamp != NULL) { @@ -243,6 +244,7 @@ void nm_ap_list_update_network (NMAccessPointList *list, const char *network, NM nm_ap_set_essid (ap, essid); nm_ap_set_enc_key_source (ap, key); nm_ap_set_timestamp (ap, timestamp); + nm_ap_set_trusted (ap, trusted); g_free (timestamp); } @@ -271,7 +273,7 @@ void nm_ap_list_populate (NMAccessPointList *list, NMData *data) g_return_if_fail (list != NULL); g_return_if_fail (data != NULL); - g_return_if_fail (((list->type == NETWORK_TYPE_TRUSTED) || (list->type == NETWORK_TYPE_PREFERRED))); + g_return_if_fail (list->type == NETWORK_TYPE_ALLOWED); networks = nm_dbus_get_networks (data->dbus_connection, list->type, &num_networks); if (networks && (num_networks > 0)) diff --git a/src/NetworkManagerAPList.h b/src/NetworkManagerAPList.h index 4ea89eb30d..ecdc6b0856 100644 --- a/src/NetworkManagerAPList.h +++ b/src/NetworkManagerAPList.h @@ -29,8 +29,7 @@ typedef enum { NETWORK_TYPE_UNKNOWN = 0, - NETWORK_TYPE_TRUSTED, - NETWORK_TYPE_PREFERRED, + NETWORK_TYPE_ALLOWED, NETWORK_TYPE_INVALID, NETWORK_TYPE_DEVICE } NMNetworkType; diff --git a/src/NetworkManagerDbus.c b/src/NetworkManagerDbus.c index 92c7d74802..88d88c48f3 100644 --- a/src/NetworkManagerDbus.c +++ b/src/NetworkManagerDbus.c @@ -707,7 +707,7 @@ GTimeVal *nm_dbus_get_network_timestamp (DBusConnection *connection, NMNetworkTy DBUS_TYPE_INT32, (int)type, DBUS_TYPE_INVALID); - /* Send message and get prio back from NetworkManagerInfo */ + /* Send message and get timestamp back from NetworkManagerInfo */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); if (dbus_error_is_set (&error)) @@ -735,6 +735,64 @@ GTimeVal *nm_dbus_get_network_timestamp (DBusConnection *connection, NMNetworkTy } +/* + * nm_dbus_get_network_trusted + * + * Get whether or not a network is a "trusted" network from NetworkManagerInfo + * + * Returns: FALSE on error or if network is not trusted + * TRUE if the network is trusted + * + */ +gboolean nm_dbus_get_network_trusted (DBusConnection *connection, NMNetworkType type, const char *network) +{ + DBusMessage *message; + DBusError error; + DBusMessage *reply; + gboolean trusted = FALSE; + + g_return_val_if_fail (connection != NULL, FALSE); + g_return_val_if_fail (network != NULL, FALSE); + g_return_val_if_fail (type != NETWORK_TYPE_UNKNOWN, FALSE); + + message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, + NMI_DBUS_INTERFACE, "getNetworkTrusted"); + if (!message) + { + syslog (LOG_ERR, "nm_dbus_get_network_trusted(): Couldn't allocate the dbus message"); + return (FALSE); + } + + dbus_message_append_args (message, DBUS_TYPE_STRING, network, + DBUS_TYPE_INT32, (int)type, + DBUS_TYPE_INVALID); + + /* Send message and get trusted status back from NetworkManagerInfo */ + dbus_error_init (&error); + reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); + if (dbus_error_is_set (&error)) + { + syslog (LOG_ERR, "nm_dbus_get_network_trusted(): %s raised %s", error.name, error.message); + dbus_error_free (&error); + } + else if (!reply) + syslog (LOG_NOTICE, "nm_dbus_get_network_trusted(): reply was NULL."); + else + { + dbus_error_init (&error); + dbus_message_get_args (reply, &error, DBUS_TYPE_BOOLEAN, &trusted, DBUS_TYPE_INVALID); + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + } + + dbus_message_unref (message); + if (reply) + dbus_message_unref (reply); + + return (trusted); +} + + /* * nm_dbus_get_networks * @@ -812,11 +870,8 @@ static DBusHandlerResult nm_dbus_nmi_filter (DBusConnection *connection, DBusMes /* syslog (LOG_DEBUG, "nm_dbus_nmi_filter() got method %s for path %s", method, object_path); */ if ( (strcmp (object_path, NMI_DBUS_PATH) == 0) - && dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "TrustedNetworkUpdate")) - list = data->trusted_ap_list; - else if ( (strcmp (object_path, NMI_DBUS_PATH) == 0) - && dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "PreferredNetworkUpdate")) - list = data->preferred_ap_list; + && dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "WirelessNetworkUpdate")) + list = data->allowed_ap_list; else if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceCreated")) { char *service; diff --git a/src/NetworkManagerDbus.h b/src/NetworkManagerDbus.h index b6f52407fe..b09e31b6ee 100644 --- a/src/NetworkManagerDbus.h +++ b/src/NetworkManagerDbus.h @@ -70,6 +70,8 @@ char * nm_dbus_get_network_key (DBusConnection *connection, NMNetworkType ty GTimeVal * nm_dbus_get_network_timestamp (DBusConnection *connection, NMNetworkType type, const char *network); +gboolean nm_dbus_get_network_trusted (DBusConnection *connection, NMNetworkType type, const char *network); + char ** nm_dbus_get_networks (DBusConnection *connection, NMNetworkType type, int *num_networks); #endif diff --git a/src/NetworkManagerDevice.c b/src/NetworkManagerDevice.c index 3f522e73d7..786e38e20b 100644 --- a/src/NetworkManagerDevice.c +++ b/src/NetworkManagerDevice.c @@ -75,6 +75,15 @@ typedef union NMDeviceOptions } NMDeviceOptions; +typedef struct NMDeviceConfigInfo +{ + gboolean use_dhcp; + guint32 ip4_gateway; + guint32 ip4_address; + guint32 ip4_netmask; + /* FIXME: ip6 stuff */ +} NMDeviceConfigInfo; + /* * NetworkManager device structure */ @@ -90,6 +99,7 @@ struct NMDevice /* FIXME: ipv6 address too */ NMData *app_data; NMDeviceOptions options; + NMDeviceConfigInfo config_info; gboolean activating; gboolean just_activated; @@ -284,6 +294,7 @@ NMDevice *nm_device_new (const char *iface, gboolean test_dev, NMDeviceType test dev->type = nm_device_test_wireless_extensions (dev) ? DEVICE_TYPE_WIRELESS_ETHERNET : DEVICE_TYPE_WIRED_ETHERNET; + /* Initialize wireless-specific options */ if (nm_device_is_wireless (dev)) { if (!(dev->options.wireless.scan_mutex = g_mutex_new ())) @@ -311,6 +322,9 @@ NMDevice *nm_device_new (const char *iface, gboolean test_dev, NMDeviceType test dev->options.wireless.supports_wireless_scan = nm_device_supports_wireless_scan (dev); } + /* Grab IP config data for this device from the system configuration files */ + nm_system_device_update_config_info (dev); + /* Have to bring the device up before checking link status. */ if (!nm_device_is_up (dev)) nm_device_bring_up (dev); @@ -548,6 +562,7 @@ void nm_device_update_link_active (NMDevice *dev, gboolean check_mii) case DEVICE_TYPE_WIRED_ETHERNET: link = nm_device_wired_link_active (dev, check_mii); + break; default: link = nm_device_get_link_active (dev); /* Can't get link info for this device, so don't change link status */ @@ -998,7 +1013,7 @@ gboolean nm_device_activation_begin (NMDevice *dev) /* - * nm_device_wireless_activate + * nm_device_activate_wireless * * Bring up a wireless card with the essid and wep key of its "best" ap * @@ -1033,6 +1048,7 @@ static gboolean nm_device_activate_wireless (NMDevice *dev) if (nm_ap_get_encrypted (best_ap) && nm_ap_get_enc_key_source (best_ap)) { char *hashed_key = nm_ap_get_enc_key_hashed (best_ap, nm_ap_get_enc_method (best_ap)); +fprintf( stderr, "hashed key = '%s'\n", hashed_key ); nm_device_set_enc_key (dev, hashed_key); g_free (hashed_key); } @@ -1079,6 +1095,43 @@ gboolean nm_device_activation_cancel_if_needed (NMDevice *dev) } +/* + * nm_device_activation_configure_ip + * + * Perform any IP-based configuration on a device, like running DHCP + * or manually setting up the IP address, gateway, and default route. + * + */ +void nm_device_activation_configure_ip (NMDevice *dev) +{ + g_return_if_fail (dev != NULL); + + if (nm_device_config_get_use_dhcp (dev)) + { + if (!nm_system_device_run_dhcp (dev)) + { + /* Interfaces cannot be down if they are the active interface, + * otherwise we cannot use them for scanning or link detection. + * If dhclient doesn't get a DHCP address, it will take the interface + * down, so we reactivate it here. + */ + if (nm_device_is_wireless (dev)) + { + nm_device_set_essid (dev, ""); + nm_device_set_enc_key (dev, NULL); + } + + nm_device_bring_up (dev); + } + } + else + { + /* Manually set up the device */ + /* FIXME: implement */ + } +} + + /* * nm_device_activation_worker * @@ -1113,11 +1166,16 @@ static gpointer nm_device_activation_worker (gpointer user_data) if ((best_ap = nm_device_get_best_ap (dev))) { - /* WEP key we have is wrong, ask user for one */ -fprintf( stderr, "(!switch (%d) || !enc_source (%d)) && is_enc (%d)\n", -!nm_device_need_ap_switch (dev), !nm_ap_get_enc_key_source (best_ap), nm_ap_get_encrypted (best_ap)); - if ( (!nm_device_need_ap_switch (dev) || !nm_ap_get_enc_key_source (best_ap)) - && nm_ap_get_encrypted (best_ap)) +fprintf( stderr, "(!switch (%d) || !enc_source (%d) || !enc_method_good (%d)) && is_enc (%d)\n", +!nm_device_need_ap_switch (dev), !nm_ap_get_enc_key_source (best_ap), +nm_ap_get_enc_method_good (best_ap), nm_ap_get_encrypted (best_ap)); + /* Something is bad with the encryption key, try falling back to a different + * method of encryption or asking the user for a new key. + */ + if ( nm_ap_get_encrypted (best_ap) + && ( !nm_device_need_ap_switch (dev) + || !nm_ap_get_enc_key_source (best_ap) + || !nm_ap_get_enc_method_good (best_ap))) { gboolean ask_for_key = TRUE; @@ -1146,6 +1204,7 @@ fprintf( stderr, "(!switch (%d) || !enc_source (%d)) && is_enc (%d)\n", } } + /* If all fallbacks for encryption method fail, ask the user for a new WEP key */ if (ask_for_key) { dev->options.wireless.user_key_received = FALSE; @@ -1199,21 +1258,7 @@ fprintf (stderr, "sleeping due to no access point\n"); /* Save machine host name */ host_err = gethostname (&hostname[0], 100); - if (!nm_system_device_run_dhcp (dev)) - { - /* Interfaces cannot be down if they are the active interface, - * otherwise we cannot use them for scanning or link detection. - * If dhclient doesn't get a DHCP address, it will take the interface - * down, so we reactivate it here. - */ - if (nm_device_is_wireless (dev)) - { - nm_device_set_essid (dev, ""); - nm_device_set_enc_key (dev, NULL); - } - - nm_device_bring_up (dev); - } + nm_device_activation_configure_ip (dev); /* Set the hostname back to what it was before so that X11 doesn't * puke when the hostname changes, and so users can actually launch stuff. @@ -1567,11 +1612,14 @@ gboolean nm_device_need_ap_switch (NMDevice *dev) */ void nm_device_update_best_ap (NMDevice *dev) { - GTimeVal latest_timestamp; NMAccessPointList *ap_list; NMAPListIter *iter; NMAccessPoint *ap = NULL; NMAccessPoint *best_ap = NULL; + NMAccessPoint *trusted_best_ap = NULL; + NMAccessPoint *untrusted_best_ap = NULL; + GTimeVal trusted_latest_timestamp = {0, 0}; + GTimeVal untrusted_latest_timestamp = {0, 0}; g_return_if_fail (dev != NULL); g_return_if_fail (dev->app_data != NULL); @@ -1580,9 +1628,6 @@ void nm_device_update_best_ap (NMDevice *dev) if (!(ap_list = nm_device_ap_list_get (dev))) return; - latest_timestamp.tv_sec = 0; - latest_timestamp.tv_usec = 0; - /* Iterate over the device's ap list to make sure the current * "best" ap is still in the device's ap list (so that if its * not, we can "unfreeze" the best ap if its been frozen already). @@ -1590,7 +1635,7 @@ void nm_device_update_best_ap (NMDevice *dev) */ if (nm_device_get_best_ap_frozen (dev)) { - best_ap = nm_device_get_best_ap (dev); + NMAccessPoint *best_ap = nm_device_get_best_ap (dev); /* If its in the device's ap list still, don't change the * best ap, since its frozen. @@ -1609,64 +1654,43 @@ void nm_device_update_best_ap (NMDevice *dev) g_mutex_unlock (dev->options.wireless.best_ap_mutex); } - /* Check the trusted list then */ if (!(iter = nm_ap_list_iter_new (ap_list))) return; while ((ap = nm_ap_list_iter_next (iter))) { - char *ap_essid = nm_ap_get_essid (ap); + NMAccessPoint *tmp_ap; + char *ap_essid = nm_ap_get_essid (ap); /* Access points in the "invalid" list cannot be used */ - if (!nm_ap_list_get_ap_by_essid (dev->app_data->invalid_ap_list, ap_essid)) + if (nm_ap_list_get_ap_by_essid (dev->app_data->invalid_ap_list, ap_essid)) + continue; + + if ((tmp_ap = nm_ap_list_get_ap_by_essid (dev->app_data->allowed_ap_list, ap_essid))) { - NMAccessPoint *tmp_ap = nm_ap_list_get_ap_by_essid (dev->app_data->trusted_ap_list, ap_essid); const GTimeVal *curtime = nm_ap_get_timestamp (tmp_ap); - /* If it exists in the trusted ap list, and it is more recent than - * access points already tested, make it the best for now. - */ - if (tmp_ap && (curtime->tv_sec > latest_timestamp.tv_sec)) + if (nm_ap_get_trusted (tmp_ap) && (curtime->tv_sec > trusted_latest_timestamp.tv_sec)) { - latest_timestamp = *nm_ap_get_timestamp (tmp_ap); - best_ap = ap; + trusted_latest_timestamp = *nm_ap_get_timestamp (tmp_ap); + trusted_best_ap = ap; + /* Merge access point data (mainly to get updated WEP key) */ + nm_ap_set_enc_key_source (trusted_best_ap, nm_ap_get_enc_key_source (tmp_ap)); + } + else if (!nm_ap_get_trusted (tmp_ap) && (curtime->tv_sec > untrusted_latest_timestamp.tv_sec)) + { + untrusted_latest_timestamp = *nm_ap_get_timestamp (tmp_ap); + untrusted_best_ap = ap; + /* Merge access point data (mainly to get updated WEP key) */ + nm_ap_set_enc_key_source (untrusted_best_ap, nm_ap_get_enc_key_source (tmp_ap)); } } } + best_ap = trusted_best_ap ? trusted_best_ap : untrusted_best_ap; nm_ap_list_iter_free (iter); - /* If its not in the trusted list, check the preferred list */ - if (!best_ap) - { - latest_timestamp.tv_sec = 0; - - if (!(iter = nm_ap_list_iter_new (ap_list))) - return; - while ((ap = nm_ap_list_iter_next (iter))) - { - char *ap_essid = nm_ap_get_essid (ap); - - /* Access points in the "invalid" list cannot be used */ - if (!nm_ap_list_get_ap_by_essid (dev->app_data->invalid_ap_list, ap_essid)) - { - NMAccessPoint *tmp_ap = nm_ap_list_get_ap_by_essid (dev->app_data->preferred_ap_list, ap_essid); - const GTimeVal *curtime = nm_ap_get_timestamp (tmp_ap); - - /* If it exists in the preferred ap list, and it is more recent than - * access points already tested, make it the best for now. - */ - if ( tmp_ap && (curtime->tv_sec > latest_timestamp.tv_sec)) - { - latest_timestamp = *nm_ap_get_timestamp (tmp_ap); - best_ap = ap; - } - } - } - nm_ap_list_iter_free (iter); - } - /* If the best ap is NULL, bring device down and clear out its essid and AP */ nm_device_set_best_ap (dev, best_ap); - if (!best_ap) + if (!nm_device_get_best_ap (dev)) { nm_device_bring_down (dev); nm_device_set_essid (dev, ""); @@ -1773,11 +1797,8 @@ static void nm_device_do_normal_scan (NMDevice *dev) if (tmp_ap->b.has_freq) nm_ap_set_freq (nm_ap, tmp_ap->b.freq); - /* Merge settings from Preferred/Allowed networks, mainly Keys */ - list_ap = nm_ap_list_get_ap_by_essid (data->trusted_ap_list, nm_ap_get_essid (nm_ap)); - if (!list_ap) - list_ap = nm_ap_list_get_ap_by_essid (data->preferred_ap_list, nm_ap_get_essid (nm_ap)); - if (list_ap) + /* Merge settings from wireless networks, mainly Keys */ + if ((list_ap = nm_ap_list_get_ap_by_essid (data->allowed_ap_list, nm_ap_get_essid (nm_ap)))) { nm_ap_set_timestamp (nm_ap, nm_ap_get_timestamp (list_ap)); nm_ap_set_enc_key_source (nm_ap, nm_ap_get_enc_key_source (list_ap)); @@ -1936,11 +1957,8 @@ static void nm_device_fake_ap_list (NMDevice *dev) nm_ap_set_quality (nm_ap, fake_qualities[i]); nm_ap_set_freq (nm_ap, fake_freqs[i]); - /* Merge settings from Preferred/Allowed networks, mainly Keys */ - list_ap = nm_ap_list_get_ap_by_essid (dev->app_data->trusted_ap_list, nm_ap_get_essid (nm_ap)); - if (!list_ap) - list_ap = nm_ap_list_get_ap_by_essid (dev->app_data->preferred_ap_list, nm_ap_get_essid (nm_ap)); - if (list_ap) + /* Merge settings from wireless networks, mainly Keys */ + if ((list_ap = nm_ap_list_get_ap_by_essid (dev->app_data->allowed_ap_list, nm_ap_get_essid (nm_ap)))) { nm_ap_set_timestamp (nm_ap, nm_ap_get_timestamp (list_ap)); nm_ap_set_enc_key_source (nm_ap, nm_ap_get_enc_key_source (list_ap)); @@ -1993,8 +2011,7 @@ void nm_device_do_wireless_scan (NMDevice *dev) */ nm_device_get_ap_address (dev, &ap_addr); if ( !nm_ethernet_address_is_valid (&ap_addr) - || !nm_ap_list_get_ap_by_essid (dev->app_data->trusted_ap_list, nm_device_get_essid (dev)) - || !nm_ap_list_get_ap_by_essid (dev->app_data->preferred_ap_list, nm_device_get_essid (dev)) + || !nm_ap_list_get_ap_by_essid (dev->app_data->allowed_ap_list, nm_device_get_essid (dev)) || !nm_device_get_best_ap (dev)) { nm_device_do_pseudo_scan (dev); @@ -2005,6 +2022,65 @@ void nm_device_do_wireless_scan (NMDevice *dev) } +/* System config data accessors */ + +gboolean nm_device_config_get_use_dhcp (NMDevice *dev) +{ + g_return_val_if_fail (dev != NULL, 0); + + return (dev->config_info.use_dhcp); +} + +void nm_device_config_set_use_dhcp (NMDevice *dev, gboolean use_dhcp) +{ + g_return_if_fail (dev != NULL); + + dev->config_info.use_dhcp = use_dhcp; +} + +guint32 nm_device_config_get_ip4_address (NMDevice *dev) +{ + g_return_val_if_fail (dev != NULL, 0); + + return (dev->config_info.ip4_address); +} + +void nm_device_config_set_ip4_address (NMDevice *dev, guint32 addr) +{ + g_return_if_fail (dev != NULL); + + dev->config_info.ip4_address = addr; +} + +guint32 nm_device_config_get_ip4_gateway (NMDevice *dev) +{ + g_return_val_if_fail (dev != NULL, 0); + + return (dev->config_info.ip4_gateway); +} + +void nm_device_config_set_ip4_gateway (NMDevice *dev, guint32 gateway) +{ + g_return_if_fail (dev != NULL); + + dev->config_info.ip4_gateway = gateway; +} + +guint32 nm_device_config_get_ip4_netmask (NMDevice *dev) +{ + g_return_val_if_fail (dev != NULL, 0); + + return (dev->config_info.ip4_netmask); +} + +void nm_device_config_set_ip4_netmask (NMDevice *dev, guint32 netmask) +{ + g_return_if_fail (dev != NULL); + + dev->config_info.ip4_netmask = netmask; +} + + /****************************************/ /* Code ripped from HAL */ /* minor modifications made for */ diff --git a/src/NetworkManagerDevice.h b/src/NetworkManagerDevice.h index a0f6c5d38f..e5b928c5ba 100644 --- a/src/NetworkManagerDevice.h +++ b/src/NetworkManagerDevice.h @@ -91,6 +91,17 @@ void nm_device_ap_list_clear (NMDevice *dev); struct NMAccessPointList *nm_device_ap_list_get (NMDevice *dev); NMAccessPoint *nm_device_ap_list_get_ap_by_essid (NMDevice *dev, const char *essid); +/* System config data accessors */ +gboolean nm_device_config_get_use_dhcp (NMDevice *dev); +void nm_device_config_set_use_dhcp (NMDevice *dev, gboolean use_dhcp); +guint32 nm_device_config_get_ip4_address (NMDevice *dev); +void nm_device_config_set_ip4_address (NMDevice *dev, guint32 addr); +guint32 nm_device_config_get_ip4_gateway (NMDevice *dev); +void nm_device_config_set_ip4_gateway (NMDevice *dev, guint32 gateway); +guint32 nm_device_config_get_ip4_netmask (NMDevice *dev); +void nm_device_config_set_ip4_netmask (NMDevice *dev, guint32 netmask); + +/* Utility routines */ NMDevice * nm_get_device_by_udi (NMData *data, const char *udi); NMDevice * nm_get_device_by_iface (NMData *data, const char *iface); diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c index 385d30ce52..7daa9393d7 100644 --- a/src/NetworkManagerPolicy.c +++ b/src/NetworkManagerPolicy.c @@ -248,17 +248,11 @@ gboolean nm_state_modification_monitor (gpointer user_data) if (data->info_daemon_avail && data->update_ap_lists) { /* Query info daemon for network lists if its now running */ - if (data->trusted_ap_list) - nm_ap_list_unref (data->trusted_ap_list); - data->trusted_ap_list = nm_ap_list_new (NETWORK_TYPE_TRUSTED); - if (data->trusted_ap_list) - nm_ap_list_populate (data->trusted_ap_list, data); - - if (data->preferred_ap_list) - nm_ap_list_unref (data->preferred_ap_list); - data->preferred_ap_list = nm_ap_list_new (NETWORK_TYPE_PREFERRED); - if (data->preferred_ap_list) - nm_ap_list_populate (data->preferred_ap_list, data); + if (data->allowed_ap_list) + nm_ap_list_unref (data->allowed_ap_list); + data->allowed_ap_list = nm_ap_list_new (NETWORK_TYPE_ALLOWED); + if (data->allowed_ap_list) + nm_ap_list_populate (data->allowed_ap_list, data); data->update_ap_lists = FALSE; } diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index e392ab4c2c..fc46db32de 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "NetworkManager.h" #include "NetworkManagerUtils.h" diff --git a/src/NetworkManagerWireless.c b/src/NetworkManagerWireless.c index 5bdaa71172..74ada8a8b0 100644 --- a/src/NetworkManagerWireless.c +++ b/src/NetworkManagerWireless.c @@ -34,24 +34,36 @@ #include "NetworkManagerUtils.h" -static char * -nm_md5 (const char *buf, size_t len) +/* + * nm_wireless_md5_digest_to_ascii + * + * Convert an MD5 digest into an ascii string suitable for use + * as a WEP key. + * + * Code originally by Alex Larsson and + * copyright Red Hat, Inc. under terms of the LGPL. + * + */ +static char *nm_wireless_md5_digest_to_ascii (unsigned char digest[16]) { -#ifdef HAVE_GCRYPT - char ascii_key[32]; - gcry_md_hash_buffer (GCRY_MD_MD5, ascii_key, buf, len); - return g_strndup (ascii_key, 32); -#else - struct GnomeKeyringMD5Context ctx; - char digest[16]; - - gnome_keyring_md5_init (&ctx); - gnome_keyring_md5_update (&ctx, buf, len); - gnome_keyring_md5_final (digest, &ctx); - return gnome_keyring_md5_digest_to_ascii (digest); -#endif + static char hex_digits[] = "0123456789abcdef"; + unsigned char *res; + int i; + + res = g_malloc (33); + for (i = 0; i < 16; i++) + { + res[2*i] = hex_digits[digest[i] >> 4]; + res[2*i+1] = hex_digits[digest[i] & 0xf]; + } + + /* We chomp it at byte 26, since WEP keys only use 104 bits */ + res[26] = 0; + + return (res); } + /* * nm_wireless_128bit_key_from_passphrase * @@ -61,9 +73,10 @@ nm_md5 (const char *buf, size_t len) */ char *nm_wireless_128bit_key_from_passphrase (char *passphrase) { - char temp_buf [65]; - int passphrase_len; - int i; + char md5_data[65]; + unsigned char digest[16]; + int passphrase_len; + int i; g_return_val_if_fail (passphrase != NULL, NULL); @@ -73,9 +86,17 @@ char *nm_wireless_128bit_key_from_passphrase (char *passphrase) /* Get at least 64 bits */ for (i = 0; i < 64; i++) - temp_buf [i] = passphrase [i % passphrase_len]; + md5_data [i] = passphrase [i % passphrase_len]; - return nm_md5 (temp_buf, 64); + /* Null terminate md5 data-to-hash and hash it */ + md5_data[64] = 0; +#ifdef HAVE_GCRYPT + gcry_md_hash_buffer (GCRY_MD_MD5, digest, md5_data, 64); +#else + gnome_keyring_md5_string (md5_data, digest); +#endif + + return (nm_wireless_md5_digest_to_ascii (digest)); } diff --git a/src/backends/NetworkManagerDebian.c b/src/backends/NetworkManagerDebian.c index fbc5d5f4b7..710a4f4c4d 100644 --- a/src/backends/NetworkManagerDebian.c +++ b/src/backends/NetworkManagerDebian.c @@ -222,3 +222,14 @@ void nm_system_load_device_modules (void) } +/* + * nm_system_device_update_config_info + * + * Retrieve any relevant configuration info for a particular device + * from the system network configuration information. Clear out existing + * info before setting stuff too. + * + */ +void nm_system_device_update_config_info (NMDevice *dev) +{ +} diff --git a/src/backends/NetworkManagerGentoo.c b/src/backends/NetworkManagerGentoo.c index 30e65b8271..4ad0a42ad5 100644 --- a/src/backends/NetworkManagerGentoo.c +++ b/src/backends/NetworkManagerGentoo.c @@ -235,3 +235,15 @@ void nm_system_update_dns (void) void nm_system_load_device_modules (void) { } + +/* + * nm_system_device_update_config_info + * + * Retrieve any relevant configuration info for a particular device + * from the system network configuration information. Clear out existing + * info before setting stuff too. + * + */ +void nm_system_device_update_config_info (NMDevice *dev) +{ +} diff --git a/src/backends/NetworkManagerRedHat.c b/src/backends/NetworkManagerRedHat.c index d220a80d6b..0280d2c21d 100644 --- a/src/backends/NetworkManagerRedHat.c +++ b/src/backends/NetworkManagerRedHat.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "NetworkManagerSystem.h" #include "NetworkManagerUtils.h" #include "NetworkManagerDevice.h" @@ -37,6 +38,7 @@ void nm_system_init (void) { } + /* * nm_system_device_run_dhcp * @@ -159,6 +161,19 @@ void nm_system_device_flush_addresses (NMDevice *dev) } +/* + * nm_system_device_setup_ip_config + * + * Set up the device with a particular IPv4 address/netmask/gateway. + * + */ +void nm_system_device_setup_ip4_config (NMDevice *dev) +{ + g_return_if_fail (dev != NULL); + g_return_if_fail (!nm_device_config_get_use_dhcp (dev)); +} + + /* * nm_system_enable_loopback * @@ -223,3 +238,88 @@ void nm_system_load_device_modules (void) } +/* + * nm_system_device_update_config_info + * + * Retrieve any relevant configuration info for a particular device + * from the system network configuration information. Clear out existing + * info before setting stuff too. + * + */ +void nm_system_device_update_config_info (NMDevice *dev) +{ + char *cfg_file_path = NULL; + FILE *file = NULL; + char buffer[100]; + gboolean data_good = FALSE; + gboolean use_dhcp = TRUE; + guint32 ip4_address = 0; + guint32 ip4_netmask = 0; + guint32 ip4_gateway = 0; + + g_return_if_fail (dev != NULL); + + /* We use DHCP on an interface unless told not to */ + nm_device_config_set_use_dhcp (dev, TRUE); + nm_device_config_set_ip4_address (dev, 0); + nm_device_config_set_ip4_gateway (dev, 0); + nm_device_config_set_ip4_netmask (dev, 0); + + /* Red Hat/Fedora Core systems store this information in + * /etc/sysconfig/network-scripts/ifcfg-* where * is the interface + * name. + */ + + cfg_file_path = g_strdup_printf ("/etc/sysconfig/network-scripts/ifcfg-%s", nm_device_get_iface (dev)); + if (!cfg_file_path) + return; + + if (!(file = fopen (cfg_file_path, "r"))) + { + g_free (cfg_file_path); + return; + } + + while (fgets (buffer, 499, file) && !feof (file)) + { + /* Kock off newline if any */ + g_strstrip (buffer); + + if (strncmp (buffer, "DEVICE=", 7) == 0) + { + /* Make sure this config file is for this device */ + if (strcmp (&buffer[7], nm_device_get_iface (dev)) != 0) + { + syslog (LOG_WARNING, "System config file '%s' was not actually for device '%s'\n", + cfg_file_path, nm_device_get_iface (dev)); + break; + } + else + data_good = TRUE; + } + else if (strncmp (buffer, "BOOTPROTO=dhcp", 14) == 0) + use_dhcp = TRUE; + else if (strncmp (buffer, "BOOTPROTO=none", 14) == 0) + use_dhcp = FALSE; + else if (strncmp (buffer, "IPADDR=", 7) == 0) + ip4_address = inet_addr (&buffer[7]); + else if (strncmp (buffer, "GATEWAY=", 8) == 0) + ip4_gateway = inet_addr (&buffer[8]); + else if (strncmp (buffer, "NETMASK=", 8) == 0) + ip4_netmask = inet_addr (&buffer[8]); + } + fclose (file); + g_free (cfg_file_path); + + /* If successful, set values on the device */ + if (data_good) + { + nm_device_config_set_use_dhcp (dev, use_dhcp); + if (ip4_address) + nm_device_config_set_ip4_address (dev, ip4_address); + if (ip4_gateway) + nm_device_config_set_ip4_gateway (dev, ip4_gateway); + if (ip4_netmask) + nm_device_config_set_ip4_netmask (dev, ip4_netmask); + } +} diff --git a/src/backends/NetworkManagerSlackware.c b/src/backends/NetworkManagerSlackware.c index 84122caf47..84d60bb62d 100644 --- a/src/backends/NetworkManagerSlackware.c +++ b/src/backends/NetworkManagerSlackware.c @@ -155,6 +155,19 @@ void nm_system_device_flush_addresses (NMDevice *dev) } +/* + * nm_system_device_update_config_info + * + * Retrieve any relevant configuration info for a particular device + * from the system network configuration information. Clear out existing + * info before setting stuff too. + * + */ +void nm_system_device_update_config_info (NMDevice *dev) +{ +} + + /* * nm_system_enable_loopback * diff --git a/src/backends/NetworkManagerSystem.h b/src/backends/NetworkManagerSystem.h index b1ef34f2be..383fa4bbc7 100644 --- a/src/backends/NetworkManagerSystem.h +++ b/src/backends/NetworkManagerSystem.h @@ -38,6 +38,8 @@ void nm_system_device_flush_routes (NMDevice *dev); void nm_system_device_flush_addresses (NMDevice *dev); +void nm_system_device_update_config_info(NMDevice *dev); + void nm_system_enable_loopback (void);