From 8e6cf1e8ff089d3e7fdc8159a8497d5aa30a72c9 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 26 May 2010 00:10:42 -0700 Subject: [PATCH] keyfile: ensure wired setting gets added if it's all default values If the wired setting isn't modified at all from the default values it won't get written out anymore after 12dcc07b74cd745381bb523b7896f9cdc10fd4ef, so make sure we include it when necessary. --- system-settings/plugins/keyfile/io/reader.c | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/system-settings/plugins/keyfile/io/reader.c b/system-settings/plugins/keyfile/io/reader.c index b8e5845f68..e8d4024faa 100644 --- a/system-settings/plugins/keyfile/io/reader.c +++ b/system-settings/plugins/keyfile/io/reader.c @@ -995,17 +995,18 @@ connection_from_file (const char *filename) key_file = g_key_file_new (); if (g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &err)) { + NMSettingConnection *s_con; + NMSetting *setting; gchar **groups; gsize length; int i; gboolean vpn_secrets = FALSE; + const char *ctype; connection = nm_connection_new (); groups = g_key_file_get_groups (key_file, &length); for (i = 0; i < length; i++) { - NMSetting *setting; - /* Only read out secrets when needed */ if (!strcmp (groups[i], VPN_SECRETS_GROUP)) { vpn_secrets = TRUE; @@ -1017,6 +1018,23 @@ connection_from_file (const char *filename) nm_connection_add_setting (connection, setting); } + /* 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 (!setting && ctype) { + if (!strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME)) + setting = nm_setting_wired_new (); + + if (setting) + nm_connection_add_setting (connection, setting); + } + } + /* Handle vpn secrets after the 'vpn' setting was read */ if (vpn_secrets) { NMSettingVPN *s_vpn;