diff options
| author | Michael Biebl <biebl@debian.org> | 2018-10-20 01:30:31 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2018-10-20 01:30:31 +0200 |
| commit | 6518e361171f64bcaaa4bf868139362ed95cc2e0 (patch) | |
| tree | d2d5b53faf80646a40ec2c0c7f2a42b3959612f5 /src/settings/plugins/keyfile/nms-keyfile-writer.c | |
| parent | e126f3e804c35480c4f075777430419d6ece23da (diff) | |
New upstream version 1.14.2 upstream/1.14.2
Diffstat (limited to 'src/settings/plugins/keyfile/nms-keyfile-writer.c')
| -rw-r--r-- | src/settings/plugins/keyfile/nms-keyfile-writer.c | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c index 270a217e..df26ea60 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-writer.c +++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c @@ -34,6 +34,8 @@ #include "nms-keyfile-utils.h" #include "nms-keyfile-reader.h" +#include "nm-utils/nm-io-utils.h" + /*****************************************************************************/ typedef struct { @@ -127,7 +129,7 @@ cert_writer (NMConnection *connection, new_path = g_strdup_printf ("%s/%s-%s.%s", info->keyfile_dir, nm_connection_get_uuid (connection), cert_data->vtable->file_suffix, ext); - success = nm_utils_file_set_contents (new_path, (const gchar *) blob_data, + success = nm_utils_file_set_contents (new_path, (const char *) blob_data, blob_len, 0600, &local); if (success) { /* Write the path value to the keyfile. @@ -170,6 +172,8 @@ _handler_write (NMConnection *connection, static gboolean _internal_write_connection (NMConnection *connection, const char *keyfile_dir, + const char *profile_dir, + gboolean with_extension, uid_t owner_uid, pid_t owner_grp, const char *existing_path, @@ -187,10 +191,14 @@ _internal_write_connection (NMConnection *connection, WriteInfo info = { 0 }; GError *local_err = NULL; int errsv; + gboolean rename = force_rename; g_return_val_if_fail (!out_path || !*out_path, FALSE); g_return_val_if_fail (keyfile_dir && keyfile_dir[0] == '/', FALSE); + if (existing_path && !g_str_has_prefix (existing_path, keyfile_dir)) + rename = TRUE; + switch (_nm_connection_verify (connection, error)) { case NM_SETTING_VERIFY_NORMALIZABLE: nm_assert_not_reached (); @@ -219,10 +227,10 @@ _internal_write_connection (NMConnection *connection, /* If we have existing file path, use it. Else generate one from * connection's ID. */ - if (existing_path != NULL && !force_rename) { + if (existing_path != NULL && !rename) { path = g_strdup (existing_path); } else { - char *filename_escaped = nms_keyfile_utils_escape_filename (id); + char *filename_escaped = nms_keyfile_utils_escape_filename (id, with_extension); path = g_build_filename (keyfile_dir, filename_escaped, NULL); g_free (filename_escaped); @@ -248,7 +256,7 @@ _internal_write_connection (NMConnection *connection, else filename = g_strdup_printf ("%s-%s-%u", id, nm_connection_get_uuid (connection), i); - filename_escaped = nms_keyfile_utils_escape_filename (filename); + filename_escaped = nms_keyfile_utils_escape_filename (filename, with_extension); g_free (path); path = g_strdup_printf ("%s/%s", keyfile_dir, filename_escaped); @@ -297,17 +305,12 @@ _internal_write_connection (NMConnection *connection, return FALSE; } - if (out_path && g_strcmp0 (existing_path, path)) { - *out_path = path; /* pass path out to caller */ - path = NULL; - } - if (out_reread || out_reread_same) { gs_unref_object NMConnection *reread = NULL; gboolean reread_same = FALSE; - reread = nms_keyfile_reader_from_keyfile (key_file, path, FALSE, NULL); + reread = nms_keyfile_reader_from_keyfile (key_file, path, NULL, profile_dir, FALSE, NULL); nm_assert (NM_IS_CONNECTION (reread)); @@ -333,11 +336,14 @@ _internal_write_connection (NMConnection *connection, NM_SET_OUT (out_reread_same, reread_same); } + NM_SET_OUT (out_path, g_steal_pointer (&path)); + return TRUE; } gboolean nms_keyfile_writer_connection (NMConnection *connection, + gboolean save_to_disk, const char *existing_path, gboolean force_rename, char **out_path, @@ -345,9 +351,19 @@ nms_keyfile_writer_connection (NMConnection *connection, gboolean *out_reread_same, GError **error) { + const char *keyfile_dir; + + if (save_to_disk) + keyfile_dir = nms_keyfile_utils_get_path (); + else + keyfile_dir = NM_CONFIG_KEYFILE_PATH_IN_MEMORY; + return _internal_write_connection (connection, + keyfile_dir, nms_keyfile_utils_get_path (), - 0, 0, + TRUE, + 0, + 0, existing_path, force_rename, out_path, @@ -368,7 +384,10 @@ nms_keyfile_writer_test_connection (NMConnection *connection, { return _internal_write_connection (connection, keyfile_dir, - owner_uid, owner_grp, + keyfile_dir, + FALSE, + owner_uid, + owner_grp, NULL, FALSE, out_path, |