summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-10-02 19:44:31 +0200
committerThomas Haller <thaller@redhat.com>2018-10-19 00:14:54 +0200
commit0642fc2d352e73141b2002b64a1a1ab9c4e629f8 (patch)
tree8ab92cff79a43716d2e2cf300bdc75ebe7a1d990
parent1460ce9f51c5f791b6f57c7474e1faee37a1a086 (diff)
downloadNetworkManager-0642fc2d352e73141b2002b64a1a1ab9c4e629f8.tar.gz
keyfile: refactor setting default ID/UUID in nm_keyfile_read()
Split out the functionality for auto-detecting the ID and UUID of a connection. First of all, nm_keyfile_read() is already overcomplicated. The next commit will require the caller to explicitly call these functions. (cherry picked from commit 02c8844178380c5f4cc1c6aa971f90cfea2be0dc)
-rw-r--r--libnm-core/nm-keyfile-internal.h6
-rw-r--r--libnm-core/nm-keyfile.c59
2 files changed, 51 insertions, 14 deletions
diff --git a/libnm-core/nm-keyfile-internal.h b/libnm-core/nm-keyfile-internal.h
index d6a1471162..a620d9aa1c 100644
--- a/libnm-core/nm-keyfile-internal.h
+++ b/libnm-core/nm-keyfile-internal.h
@@ -101,6 +101,12 @@ NMConnection *nm_keyfile_read (GKeyFile *keyfile,
void *user_data,
GError **error);
+gboolean nm_keyfile_read_ensure_id (NMConnection *connection,
+ const char *fallback_id);
+
+gboolean nm_keyfile_read_ensure_uuid (NMConnection *connection,
+ const char *fallback_uuid_seed);
+
/*****************************************************************************/
typedef enum {
diff --git a/libnm-core/nm-keyfile.c b/libnm-core/nm-keyfile.c
index c7d878691b..ee4386ad40 100644
--- a/libnm-core/nm-keyfile.c
+++ b/libnm-core/nm-keyfile.c
@@ -2812,6 +2812,46 @@ read_vpn_secrets (KeyfileReaderInfo *info, NMSettingVpn *s_vpn)
}
}
+gboolean
+nm_keyfile_read_ensure_id (NMConnection *connection,
+ const char *fallback_id)
+{
+ NMSettingConnection *s_con;
+
+ g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (fallback_id, FALSE);
+
+ s_con = nm_connection_get_setting_connection (connection);
+ g_return_val_if_fail (NM_IS_SETTING_CONNECTION (s_con), FALSE);
+
+ if (nm_setting_connection_get_id (s_con))
+ return FALSE;
+
+ g_object_set (s_con, NM_SETTING_CONNECTION_ID, fallback_id, NULL);
+ return TRUE;
+}
+
+gboolean
+nm_keyfile_read_ensure_uuid (NMConnection *connection,
+ const char *fallback_uuid_seed)
+{
+ NMSettingConnection *s_con;
+ gs_free char *hashed_uuid = NULL;
+
+ g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (fallback_uuid_seed, FALSE);
+
+ s_con = nm_connection_get_setting_connection (connection);
+ g_return_val_if_fail (NM_IS_SETTING_CONNECTION (s_con), FALSE);
+
+ if (nm_setting_connection_get_uuid (s_con))
+ return FALSE;
+
+ hashed_uuid = _nm_utils_uuid_generate_from_strings ("keyfile", fallback_uuid_seed, NULL);
+ g_object_set (s_con, NM_SETTING_CONNECTION_UUID, hashed_uuid, NULL);
+ return TRUE;
+}
+
/**
* nm_keyfile_read:
* @keyfile: the keyfile from which to create the connection
@@ -2902,23 +2942,14 @@ nm_keyfile_read (GKeyFile *keyfile,
nm_connection_add_setting (connection, NM_SETTING (s_con));
}
- /* Make sure that we have 'id' even if not explictly specified in the keyfile */
- if ( keyfile_name
- && !nm_setting_connection_get_id (s_con)) {
- gs_free char *base_name = NULL;
+ if (keyfile_name) {
+ gs_free char *basename = g_path_get_basename (keyfile_name);
- base_name = g_path_get_basename (keyfile_name);
- g_object_set (s_con, NM_SETTING_CONNECTION_ID, base_name, NULL);
+ nm_keyfile_read_ensure_id (connection, basename);
}
- /* Make sure that we have 'uuid' even if not explictly specified in the keyfile */
- if ( keyfile_name
- && !nm_setting_connection_get_uuid (s_con)) {
- gs_free char *hashed_uuid = NULL;
-
- hashed_uuid = _nm_utils_uuid_generate_from_strings ("keyfile", keyfile_name, NULL);
- g_object_set (s_con, NM_SETTING_CONNECTION_UUID, hashed_uuid, NULL);
- }
+ if (keyfile_name)
+ nm_keyfile_read_ensure_uuid (connection, keyfile_name);
/* Make sure that we have 'interface-name' even if it was specified in the
* "wrong" (ie, deprecated) group.