mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 13:08:10 +02:00
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 02c8844178)
This commit is contained in:
parent
1460ce9f51
commit
0642fc2d35
2 changed files with 51 additions and 14 deletions
|
|
@ -101,6 +101,12 @@ NMConnection *nm_keyfile_read (GKeyFile *keyfile,
|
||||||
void *user_data,
|
void *user_data,
|
||||||
GError **error);
|
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 {
|
typedef enum {
|
||||||
|
|
|
||||||
|
|
@ -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:
|
* nm_keyfile_read:
|
||||||
* @keyfile: the keyfile from which to create the connection
|
* @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));
|
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) {
|
||||||
if ( keyfile_name
|
gs_free char *basename = g_path_get_basename (keyfile_name);
|
||||||
&& !nm_setting_connection_get_id (s_con)) {
|
|
||||||
gs_free char *base_name = NULL;
|
|
||||||
|
|
||||||
base_name = g_path_get_basename (keyfile_name);
|
nm_keyfile_read_ensure_id (connection, basename);
|
||||||
g_object_set (s_con, NM_SETTING_CONNECTION_ID, base_name, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure that we have 'uuid' even if not explictly specified in the keyfile */
|
if (keyfile_name)
|
||||||
if ( keyfile_name
|
nm_keyfile_read_ensure_uuid (connection, 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make sure that we have 'interface-name' even if it was specified in the
|
/* Make sure that we have 'interface-name' even if it was specified in the
|
||||||
* "wrong" (ie, deprecated) group.
|
* "wrong" (ie, deprecated) group.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue