Merge remote branch 'origin/master' into rm-userset
authorDan Williams <dcbw@redhat.com>
Thu, 16 Sep 2010 22:10:49 +0000 (17:10 -0500)
committerDan Williams <dcbw@redhat.com>
Thu, 16 Sep 2010 22:10:49 +0000 (17:10 -0500)
1  2 
include/NetworkManager.h
man/nmcli.1.in
po/POTFILES.in
src/nm-device.c
src/nm-manager.c
src/nm-policy.c
src/vpn-manager/nm-vpn-connection.c
system-settings/plugins/keyfile/io/reader.c
system-settings/plugins/keyfile/nm-keyfile-connection.c
system-settings/plugins/keyfile/plugin.c

Simple merge
diff --cc man/nmcli.1.in
Simple merge
diff --cc po/POTFILES.in
Simple merge
diff --cc src/nm-device.c
Simple merge
  #define NM_AUTOIP_DBUS_SERVICE "org.freedesktop.nm_avahi_autoipd"
  #define NM_AUTOIP_DBUS_IFACE   "org.freedesktop.nm_avahi_autoipd"
  
+ #define UPOWER_DBUS_SERVICE "org.freedesktop.UPower"
  static gboolean impl_manager_get_devices (NMManager *manager, GPtrArray **devices, GError **err);
  static void impl_manager_activate_connection (NMManager *manager,
 -                                              const char *service_name,
                                                const char *connection_path,
                                                const char *device_path,
                                                const char *specific_object_path,
diff --cc src/nm-policy.c
Simple merge
Simple merge
@@@ -40,6 -40,7 +40,7 @@@
  #include <arpa/inet.h>
  #include <netinet/ether.h>
  #include <string.h>
 -#include <nm-settings-interface.h>
++#include <nm-system-config-error.h>
  
  #include "nm-dbus-glib-types.h"
  #include "reader.h"
@@@ -992,102 -993,120 +993,120 @@@ connection_from_file (const char *filen
        struct stat statbuf;
        gboolean bad_owner, bad_permissions;
        NMConnection *connection = NULL;
-       GError *err = NULL;
-       if (stat (filename, &statbuf) != 0 || !S_ISREG (statbuf.st_mode))
+       NMSettingConnection *s_con;
+       NMSettingBluetooth *s_bt;
+       NMSetting *setting;
+       gchar **groups;
+       gsize length;
+       int i;
+       gboolean vpn_secrets = FALSE;
+       const char *ctype, *tmp;
+       GError *verify_error = NULL;
+       if (stat (filename, &statbuf) != 0 || !S_ISREG (statbuf.st_mode)) {
+               g_set_error_literal (error,
 -                                   NM_SETTINGS_INTERFACE_ERROR,
 -                                   NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
++                                   NM_SYSCONFIG_SETTINGS_ERROR,
++                                   NM_SYSCONFIG_SETTINGS_ERROR_INTERNAL_ERROR,
+                                    "File did not exist or was not a regular file");
                return NULL;
+       }
  
        bad_owner = getuid () != statbuf.st_uid;
        bad_permissions = statbuf.st_mode & 0077;
  
        if (bad_owner || bad_permissions) {
-               g_warning ("Ignoring insecure configuration file '%s'", filename);
+               g_set_error (error,
 -                           NM_SETTINGS_INTERFACE_ERROR,
 -                           NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
++                           NM_SYSCONFIG_SETTINGS_ERROR,
++                           NM_SYSCONFIG_SETTINGS_ERROR_INTERNAL_ERROR,
+                            "File permissions (%o) or owner (%d) were insecure",
+                            statbuf.st_mode, statbuf.st_uid);
                return NULL;
        }
  
        key_file = g_key_file_new ();
-       if (g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &err)) {
-               NMSettingConnection *s_con;
-               NMSettingBluetooth *s_bt;
-               NMSetting *setting;
-               gchar **groups;
-               gsize length;
-               int i;
-               gboolean vpn_secrets = FALSE;
-               const char *ctype, *tmp;
-               connection = nm_connection_new ();
+       if (!g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, error))
+               goto out;
  
-               groups = g_key_file_get_groups (key_file, &length);
-               for (i = 0; i < length; i++) {
-                       /* Only read out secrets when needed */
-                       if (!strcmp (groups[i], VPN_SECRETS_GROUP)) {
-                               vpn_secrets = TRUE;
-                               continue;
-                       }
+       connection = nm_connection_new ();
  
-                       setting = read_setting (key_file, groups[i]);
-                       if (setting)
-                               nm_connection_add_setting (connection, setting);
+       groups = g_key_file_get_groups (key_file, &length);
+       for (i = 0; i < length; i++) {
+               /* Only read out secrets when needed */
+               if (!strcmp (groups[i], VPN_SECRETS_GROUP)) {
+                       vpn_secrets = TRUE;
+                       continue;
                }
  
-               /* Make sure that we have the base device type setting even if
-                * the keyfile didn't include it, which can happen when the base
-                * device type setting is all default values (like ethernet).
-                */
-               s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
-               if (s_con) {
-                       ctype = nm_setting_connection_get_connection_type (s_con);
-                       setting = nm_connection_get_setting_by_name (connection, ctype);
-                       if (ctype) {
-                               gboolean add_serial = FALSE;
-                               NMSetting *new_setting = NULL;
-                               if (!setting && !strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME))
-                                       new_setting = nm_setting_wired_new ();
-                               else if (!strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME)) {
-                                       s_bt = (NMSettingBluetooth *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH);
-                                       if (s_bt) {
-                                               tmp = nm_setting_bluetooth_get_connection_type (s_bt);
-                                               if (tmp && !strcmp (tmp, NM_SETTING_BLUETOOTH_TYPE_DUN))
-                                                       add_serial = TRUE;
-                                       }
-                               } else if (!strcmp (ctype, NM_SETTING_GSM_SETTING_NAME))
-                                       add_serial = TRUE;
-                               else if (!strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME))
-                                       add_serial = TRUE;
-                               /* Bluetooth DUN, GSM, and CDMA connections require a serial setting */
-                               if (add_serial && !nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL))
-                                       new_setting = nm_setting_serial_new ();
-                               if (new_setting)
-                                       nm_connection_add_setting (connection, new_setting);
-                       }
-               }
+               setting = read_setting (key_file, groups[i]);
+               if (setting)
+                       nm_connection_add_setting (connection, setting);
+       }
  
-               /* Serial connections require a PPP setting too */
-               if (nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL)) {
-                       if (!nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP))
-                               nm_connection_add_setting (connection, nm_setting_ppp_new ());
-               }
+       /* Make sure that we have the base device type setting even if
+        * the keyfile didn't include it, which can happen when the base
+        * device type setting is all default values (like ethernet).
+        */
+       s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+       if (s_con) {
+               ctype = nm_setting_connection_get_connection_type (s_con);
+               setting = nm_connection_get_setting_by_name (connection, ctype);
+               if (ctype) {
+                       gboolean add_serial = FALSE;
+                       NMSetting *new_setting = NULL;
+                       if (!setting && !strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME))
+                               new_setting = nm_setting_wired_new ();
+                       else if (!strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME)) {
+                               s_bt = (NMSettingBluetooth *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH);
+                               if (s_bt) {
+                                       tmp = nm_setting_bluetooth_get_connection_type (s_bt);
+                                       if (tmp && !strcmp (tmp, NM_SETTING_BLUETOOTH_TYPE_DUN))
+                                               add_serial = TRUE;
+                               }
+                       } else if (!strcmp (ctype, NM_SETTING_GSM_SETTING_NAME))
+                               add_serial = TRUE;
+                       else if (!strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME))
+                               add_serial = TRUE;
  
-               /* Handle vpn secrets after the 'vpn' setting was read */
-               if (vpn_secrets) {
-                       NMSettingVPN *s_vpn;
+                       /* Bluetooth DUN, GSM, and CDMA connections require a serial setting */
+                       if (add_serial && !nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL))
+                               new_setting = nm_setting_serial_new ();
  
-                       s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
-                       if (s_vpn)
-                               read_vpn_secrets (key_file, s_vpn);
+                       if (new_setting)
+                               nm_connection_add_setting (connection, new_setting);
                }
+       }
  
-               g_strfreev (groups);
-       } else {
-               g_warning ("Error parsing file '%s': %s", filename, err->message);
-               g_error_free (err);
+       /* Serial connections require a PPP setting too */
+       if (nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL)) {
+               if (!nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP))
+                       nm_connection_add_setting (connection, nm_setting_ppp_new ());
        }
  
-       g_key_file_free (key_file);
+       /* Handle vpn secrets after the 'vpn' setting was read */
+       if (vpn_secrets) {
+               NMSettingVPN *s_vpn;
+               s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
+               if (s_vpn)
+                       read_vpn_secrets (key_file, s_vpn);
+       }
  
 -                               NM_SETTINGS_INTERFACE_ERROR,
 -                               NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
+       g_strfreev (groups);
+       /* Verify the connection */
+       if (!nm_connection_verify (connection, &verify_error)) {
+               g_set_error (error,
++                               NM_SYSCONFIG_SETTINGS_ERROR,
++                               NM_SYSCONFIG_SETTINGS_ERROR_INTERNAL_ERROR,
+                                "invalid or missing connection property '%s'",
+                                (verify_error && verify_error->message) ? verify_error->message : "(unknown)");
+               g_clear_error (&verify_error);
+               g_object_unref (connection);
+               connection = NULL;
+       }
+ out:
+       g_key_file_free (key_file);
        return connection;
  }
@@@ -24,7 -24,9 +24,8 @@@
  #include <NetworkManager.h>
  #include <nm-setting-connection.h>
  #include <nm-utils.h>
 -#include <nm-settings-connection-interface.h>
  
+ #include "nm-system-config-interface.h"
  #include "nm-dbus-glib-types.h"
  #include "nm-keyfile-connection.h"
  #include "reader.h"
@@@ -46,13 -54,55 +47,55 @@@ enum 
  };
  
  NMKeyfileConnection *
- nm_keyfile_connection_new (const char *filename)
+ nm_keyfile_connection_new (const char *filename, GError **error)
  {
+       GObject *object;
+       NMKeyfileConnectionPrivate *priv;
+       NMSettingConnection *s_con;
+       NMConnection *tmp;
        g_return_val_if_fail (filename != NULL, NULL);
  
-       return (NMKeyfileConnection *) g_object_new (NM_TYPE_KEYFILE_CONNECTION,
-                                                    NM_KEYFILE_CONNECTION_FILENAME, filename,
-                                                    NULL);
+       tmp = connection_from_file (filename, error);
+       if (!tmp)
+               return NULL;
+       object = (GObject *) g_object_new (NM_TYPE_KEYFILE_CONNECTION,
+                                          NM_KEYFILE_CONNECTION_FILENAME, filename,
+                                          NULL);
+       if (!object) {
+               g_object_unref (tmp);
+               return NULL;
+       }
+       priv = NM_KEYFILE_CONNECTION_GET_PRIVATE (object);
+       g_assert (priv->filename);
+       /* Update our settings with what was read from the file */
 -      nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (object), tmp, FALSE, NULL);
++      nm_sysconfig_connection_replace_settings (NM_SYSCONFIG_CONNECTION (object), tmp, NULL);
+       g_object_unref (tmp);
+       /* if for some reason the connection didn't have a UUID, add one */
+       s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (object), NM_TYPE_SETTING_CONNECTION);
+       if (s_con && !nm_setting_connection_get_uuid (s_con)) {
+               GError *write_error = NULL;
+               char *uuid;
+               uuid = nm_utils_uuid_generate ();
+               g_object_set (s_con, NM_SETTING_CONNECTION_UUID, uuid, NULL);
+               g_free (uuid);
+               if (!write_connection (NM_CONNECTION (object), KEYFILE_DIR, 0, 0, NULL, &write_error)) {
+                       PLUGIN_WARN (KEYFILE_PLUGIN_NAME,
+                                    "Couldn't update connection %s with a UUID: (%d) %s",
+                                    nm_setting_connection_get_id (s_con),
+                                    write_error ? write_error->code : -1,
+                                    (write_error && write_error->message) ? write_error->message : "(unknown)");
+                       g_propagate_error (error, write_error);
+               }
+       }
+       return NM_KEYFILE_CONNECTION (object);
  }
  
  const char *
@@@ -138,23 -163,29 +156,38 @@@ update_connection_settings_commit_cb (N
        }
  }
  
 +static void
 +update_connection_settings (NMKeyfileConnection *orig,
 +                            NMKeyfileConnection *new)
 +{
 +      nm_sysconfig_connection_replace_and_commit (NM_SYSCONFIG_CONNECTION (orig),
 +                                                  NM_CONNECTION (new),
 +                                                  update_connection_settings_commit_cb, NULL);
 +}
 +
  /* Monitoring */
  
+ static void
+ remove_connection (SCPluginKeyfile *self,
+                    NMKeyfileConnection *connection,
+                    const char *name)
+ {
+       g_return_if_fail (connection != NULL);
+       g_return_if_fail (name != NULL);
+       /* Removing from the hash table should drop the last reference */
+       g_object_ref (connection);
+       g_hash_table_remove (SC_PLUGIN_KEYFILE_GET_PRIVATE (self)->hash, name);
+       g_signal_emit_by_name (connection, "removed");
+       g_object_unref (connection);
+ }
  static void
  dir_changed (GFileMonitor *monitor,
-                  GFile *file,
-                  GFile *other_file,
-                  GFileMonitorEvent event_type,
-                  gpointer user_data)
+              GFile *file,
+              GFile *other_file,
+              GFileMonitorEvent event_type,
+              gpointer user_data)
  {
        NMSystemConfigInterface *config = NM_SYSTEM_CONFIG_INTERFACE (user_data);
        SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config);