mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-06 17:14:02 +00:00
keyfile: allow missing 'id' and 'uuid' in [connection] section (bgo #683345)
If 'id' is missing, it is automatically filled with base file name. If 'uuid' is missing, it is automatically generated (hashing file path). https://bugzilla.gnome.org/show_bug.cgi?id=683345
This commit is contained in:
parent
4b1dd4647e
commit
c88b832ce9
|
@ -1293,6 +1293,24 @@ nm_keyfile_plugin_connection_from_file (const char *filename, GError **error)
|
|||
}
|
||||
}
|
||||
|
||||
/* 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 'uuid' even if not explictly specified in the keyfile */
|
||||
if (!nm_setting_connection_get_uuid (s_con)) {
|
||||
char *hashed_uuid;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ KEYFILES = \
|
|||
Test_Bridge_Component \
|
||||
Test_New_Wired_Group_Name \
|
||||
Test_New_Wireless_Group_Names \
|
||||
Test_Missing_Vlan_Setting
|
||||
Test_Missing_Vlan_Setting \
|
||||
Test_Missing_ID_UUID
|
||||
|
||||
CERTS = \
|
||||
test-ca-cert.pem \
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
# id and uuid keys are missing
|
||||
# They will be auto-genetrated by NetworkManager
|
||||
|
||||
[connection]
|
||||
type=ethernet
|
||||
autoconnect=true
|
||||
|
||||
[802-3-ethernet]
|
||||
mac-address=00:11:22:33:44:55
|
|
@ -3410,6 +3410,27 @@ test_read_missing_vlan_setting (void)
|
|||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_missing_id_uuid (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
GError *error = NULL;
|
||||
gboolean success;
|
||||
|
||||
connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Missing_ID_UUID", &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (connection);
|
||||
success = nm_connection_verify (connection, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
|
||||
/* Ensure the ID and UUID properties are there */
|
||||
g_assert_cmpstr (nm_connection_get_id (connection), ==, "Test_Missing_ID_UUID");
|
||||
g_assert (nm_connection_get_uuid (connection));
|
||||
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
NMTST_DEFINE ();
|
||||
|
||||
int main (int argc, char **argv)
|
||||
|
@ -3472,6 +3493,7 @@ int main (int argc, char **argv)
|
|||
test_write_new_wireless_group_names ();
|
||||
|
||||
test_read_missing_vlan_setting ();
|
||||
test_read_missing_id_uuid ();
|
||||
|
||||
base = g_path_get_basename (argv[0]);
|
||||
fprintf (stdout, "%s: SUCCESS\n", base);
|
||||
|
|
Loading…
Reference in a new issue