mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 17:08:08 +02:00
keyfile: fix two bugs for updating/writting a keyfile
* When a connection name (ID) was changed via nm-connection-editor, a new file path was created, but the old one was not removed. That resulted in two files and in turn in duplicated connections. * When two connections with the same name (ID) were present, e.g. files ABC and ABC-70656842-98ac-4221-aa8b-0d4174770, and nm-connection-editor was used to edit ABC-70656842-98ac-4221-aa8b-0d4174770, the operation failed.
This commit is contained in:
parent
b4892510b5
commit
f3d4cd385e
1 changed files with 18 additions and 6 deletions
|
|
@ -993,15 +993,27 @@ _internal_write_connection (NMConnection *connection,
|
||||||
|
|
||||||
path = g_strdup_printf ("%s/%s-%s", keyfile_dir, filename, nm_connection_get_uuid (connection));
|
path = g_strdup_printf ("%s/%s-%s", keyfile_dir, filename, nm_connection_get_uuid (connection));
|
||||||
if (g_file_test (path, G_FILE_TEST_EXISTS)) {
|
if (g_file_test (path, G_FILE_TEST_EXISTS)) {
|
||||||
/* Hmm, this is odd. Give up. */
|
if (existing_path == NULL || g_strcmp0 (path, existing_path) != 0) {
|
||||||
g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
|
/* This should not happen. But, it actually occurs when
|
||||||
"%s.%d: could not find suitable keyfile file name (%s already used)",
|
* two connections have the same UUID, and one of the connections
|
||||||
__FILE__, __LINE__, path);
|
* is edited to contain the same ID as the other one.
|
||||||
g_free (path);
|
* Give up.
|
||||||
goto out;
|
*/
|
||||||
|
g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
|
||||||
|
"%s.%d: could not find suitable keyfile file name (%s already used)",
|
||||||
|
__FILE__, __LINE__, path);
|
||||||
|
g_free (path);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* In case of updating the connection and changing the file path,
|
||||||
|
* we need to remove the old one, not to end up with two connections.
|
||||||
|
*/
|
||||||
|
if (existing_path != NULL && strcmp (path, existing_path) != 0)
|
||||||
|
unlink (existing_path);
|
||||||
|
|
||||||
g_file_set_contents (path, data, len, error);
|
g_file_set_contents (path, data, len, error);
|
||||||
if (chown (path, owner_uid, owner_grp) < 0) {
|
if (chown (path, owner_uid, owner_grp) < 0) {
|
||||||
g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
|
g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue