2004-09-08 Dan Williams <dcbw@redhat.com>
authorDan Williams <dcbw@redhat.com>
Wed, 8 Sep 2004 18:14:42 +0000 (18:14 +0000)
committerDan Williams <dcbw@redhat.com>
Wed, 8 Sep 2004 18:14:42 +0000 (18:14 +0000)
* 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

30 files changed:
ChangeLog
TODO
info-daemon/NetworkManagerInfo.c
info-daemon/NetworkManagerInfo.h
info-daemon/NetworkManagerInfoDbus.c
info-daemon/NetworkManagerInfoDbus.h
info-daemon/NetworkManagerInfoPassphraseDialog.c
info-daemon/passphrase.glade
panel-applet/Makefile.am
panel-applet/NMWirelessApplet.c
panel-applet/NMWirelessApplet.h
panel-applet/no-networkmanager.png [new file with mode: 0644]
src/NetworkManager.c
src/NetworkManager.h
src/NetworkManagerAP.c
src/NetworkManagerAP.h
src/NetworkManagerAPList.c
src/NetworkManagerAPList.h
src/NetworkManagerDbus.c
src/NetworkManagerDbus.h
src/NetworkManagerDevice.c
src/NetworkManagerDevice.h
src/NetworkManagerPolicy.c
src/NetworkManagerUtils.c
src/NetworkManagerWireless.c
src/backends/NetworkManagerDebian.c
src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerSystem.h

index a4005fe..766e09e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,61 @@
+2004-09-08  Dan Williams <dcbw@redhat.com>
+
+       * 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 <dcbw@redhat.com>
 
        * src/backends/NetworkManagerRedhat.c
diff --git a/TODO b/TODO
index 51cf1c6..b6249fd 100644 (file)
--- 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.
index 8ee7349..efd1e05 100644 (file)
@@ -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);
                }
        }
index 20d7a15..29c46ab 100644 (file)
@@ -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
index 0105429..a9ab7e6 100644 (file)
@@ -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,56 @@ static DBusMessage *nmi_dbus_get_network_key (NMIAppInfo *info, DBusMessage *mes
                return (reply_message);
        }
 
-       switch (type)
+       /* Grab user-key key for our access point from GConf */
+       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);
+
+       /* 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_STRING, gconf_value_get_string (value), DBUS_TYPE_INVALID);
+               gconf_value_free (value);
+       }
+       else
+               dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "", DBUS_TYPE_INVALID);
+
+       return (reply_message);
+}
+
+
+/*
+ * 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))
        {
-               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);
+               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/key", path, network);
+       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);
 
@@ -444,11 +448,11 @@ static DBusMessage *nmi_dbus_get_network_key (NMIAppInfo *info, DBusMessage *mes
        reply_message = dbus_message_new_method_return (message);
        if (value)
        {
-               dbus_message_append_args (reply_message, DBUS_TYPE_STRING, gconf_value_get_string (value), DBUS_TYPE_INVALID);
+               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_STRING, "", DBUS_TYPE_INVALID);
+               dbus_message_append_args (reply_message, DBUS_TYPE_BOOLEAN, FALSE, DBUS_TYPE_INVALID);
 
        return (reply_message);
 }
@@ -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);
 }
index ecdffd9..3c0206a 100644 (file)
@@ -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;
index 44ceb1d..1ee3495 100644 (file)
@@ -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);
                }
index b4d19f7..8cc1fe6 100644 (file)
@@ -6,15 +6,13 @@
 <widget class="GtkDialog" id="passphrase_dialog">
   <property name="border_width">6</property>
   <property name="has_focus">True</property>
-  <property name="title" translatable="yes"> </property>
+  <property name="title" translatable="yes">Wireless Network Key Required</property>
   <property name="type">GTK_WINDOW_TOPLEVEL</property>
   <property name="window_position">GTK_WIN_POS_CENTER_ALWAYS</property>
   <property name="modal">False</property>
   <property name="resizable">False</property>
   <property name="destroy_with_parent">False</property>
   <property name="decorated">True</property>
-  <property name="skip_taskbar_hint">True</property>
-  <property name="skip_pager_hint">True</property>
   <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
   <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
   <property name="has_separator">False</property>
index 0b33be9..9a38c7d 100644 (file)
@@ -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
index 6daaaa1..f555302 100644 (file)
 #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);
index db7d724..0f9d063 100644 (file)
@@ -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 (file)
index 0000000..e51c32c
Binary files /dev/null and b/panel-applet/no-networkmanager.png differ
index 4bc06c6..f11924d 100644 (file)
@@ -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);
-               syslogLOG_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);
-               syslogLOG_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)
index 4f60ff5..d63f8af 100644 (file)
@@ -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;
 
index 06cba0c..727d47a 100644 (file)
@@ -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;
+}
index 2815358..d8a7a12 100644 (file)
@@ -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
index 68aa104..6801d64 100644 (file)
@@ -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))
index 4ea89eb..ecdc6b0 100644 (file)
@@ -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;
index 92c7d74..88d88c4 100644 (file)
@@ -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;
index b6f5240..b09e31b 100644 (file)
@@ -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
index 3f522e7..786e38e 100644 (file)
@@ -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));
                        }
-               }
-       }
-       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))
+                       else if (!nm_ap_get_trusted (tmp_ap) && (curtime->tv_sec > untrusted_latest_timestamp.tv_sec))
                        {
-                               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;
-                               }
+                               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));
                        }
                }
-               nm_ap_list_iter_free (iter);
        }
+       best_ap = trusted_best_ap ? trusted_best_ap : untrusted_best_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       */
index a0f6c5d..e5b928c 100644 (file)
@@ -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);
 
index 385d30c..7daa939 100644 (file)
@@ -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;
        }
index e392ab4..fc46db3 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <linux/sockios.h>
+#include <syslog.h>
 
 #include "NetworkManager.h"
 #include "NetworkManagerUtils.h"
index 5bdaa71..74ada8a 100644 (file)
 #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 <alexl@redhat.com> 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];
+
+       /* 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_md5 (temp_buf, 64);
+       return (nm_wireless_md5_digest_to_ascii (digest));
 }
 
 
index fbc5d5f..710a4f4 100644 (file)
@@ -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)
+{
+}
index 30e65b8..4ad0a42 100644 (file)
@@ -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)
+{
+}
index d220a80..0280d2c 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <signal.h>
+#include <arpa/inet.h>
 #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);
+       }
+}
index 84122ca..84d60bb 100644 (file)
@@ -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
  *
index b1ef34f..383fa4b 100644 (file)
@@ -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);