summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-07-03 13:18:17 +0200
committerThomas Haller <thaller@redhat.com>2014-08-22 15:24:30 +0200
commit5f26a9c11ff44474bbaff97a811f1eb636d888b2 (patch)
treecf2dcabc7a24cdb3126d2c1e1d33b42d93211a36
parent043ab29ca949bfaf9fcaa034f86bb67ead1a666c (diff)
keyfile: add NMSettingConnection in reader if missing
The recent change c88b832ce9510bdcb2df2bf7e02b1ded88154581 allows for missing 'id' and 'uuid' entries. Further make the keyfile reader more accepting, by creating a missing NMSettingConnection. Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--src/settings/plugins/keyfile/reader.c62
1 files changed, 32 insertions, 30 deletions
diff --git a/src/settings/plugins/keyfile/reader.c b/src/settings/plugins/keyfile/reader.c
index aba232c0d5..f2a2d473a9 100644
--- a/src/settings/plugins/keyfile/reader.c
+++ b/src/settings/plugins/keyfile/reader.c
@@ -1281,44 +1281,46 @@ nm_keyfile_plugin_connection_from_file (const char *filename, GError **error)
* bridge port with all default settings).
*/
s_con = nm_connection_get_setting_connection (connection);
- if (s_con) {
- ctype = nm_setting_connection_get_connection_type (s_con);
- if (ctype) {
- setting = nm_connection_get_setting_by_name (connection, ctype);
- if (!setting) {
- NMSetting *base_setting;
- GType base_setting_type;
-
- base_setting_type = nm_setting_lookup_type (ctype);
- if (base_setting_type != G_TYPE_INVALID) {
- base_setting = (NMSetting *) g_object_new (base_setting_type, NULL);
- g_assert (base_setting);
- nm_connection_add_setting (connection, base_setting);
- }
+ if (!s_con) {
+ s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
+ nm_connection_add_setting (connection, NM_SETTING (s_con));
+ }
+ ctype = nm_setting_connection_get_connection_type (s_con);
+ if (ctype) {
+ setting = nm_connection_get_setting_by_name (connection, ctype);
+ if (!setting) {
+ NMSetting *base_setting;
+ GType base_setting_type;
+
+ base_setting_type = nm_setting_lookup_type (ctype);
+ if (base_setting_type != G_TYPE_INVALID) {
+ base_setting = (NMSetting *) g_object_new (base_setting_type, NULL);
+ g_assert (base_setting);
+ nm_connection_add_setting (connection, base_setting);
}
}
+ }
- /* Make sure that we have 'id' even if not explictly specified in the keyfile */
- if (!nm_setting_connection_get_id (s_con)) {
- char *base_name;
-
- base_name = g_path_get_basename (filename);
- g_object_set (s_con, NM_SETTING_CONNECTION_ID, base_name, NULL);
- g_free (base_name);
- }
+ /* Make sure that we have 'id' even if not explictly specified in the keyfile */
+ if (!nm_setting_connection_get_id (s_con)) {
+ char *base_name;
- /* Make sure that we have 'uuid' even if not explictly specified in the keyfile */
- if (!nm_setting_connection_get_uuid (s_con)) {
- char *hashed_uuid;
+ base_name = g_path_get_basename (filename);
+ g_object_set (s_con, NM_SETTING_CONNECTION_ID, base_name, NULL);
+ g_free (base_name);
+ }
- hashed_uuid = nm_utils_uuid_generate_from_string (filename);
- g_object_set (s_con, NM_SETTING_CONNECTION_UUID, hashed_uuid, NULL);
- g_free (hashed_uuid);
- }
+ /* Make sure that we have 'uuid' even if not explictly specified in the keyfile */
+ if (!nm_setting_connection_get_uuid (s_con)) {
+ char *hashed_uuid;
- ensure_slave_setting (connection);
+ hashed_uuid = nm_utils_uuid_generate_from_string (filename);
+ g_object_set (s_con, NM_SETTING_CONNECTION_UUID, hashed_uuid, NULL);
+ g_free (hashed_uuid);
}
+ ensure_slave_setting (connection);
+
/* Handle vpn secrets after the 'vpn' setting was read */
if (vpn_secrets) {
NMSettingVpn *s_vpn;