summaryrefslogtreecommitdiff
path: root/src/settings/plugins/ifcfg-rh/writer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings/plugins/ifcfg-rh/writer.c')
-rw-r--r--src/settings/plugins/ifcfg-rh/writer.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c
index ec174a5987..c16d7ab291 100644
--- a/src/settings/plugins/ifcfg-rh/writer.c
+++ b/src/settings/plugins/ifcfg-rh/writer.c
@@ -144,11 +144,15 @@ write_secret_file (const char *path,
char *tmppath;
int fd = -1, written;
gboolean success = FALSE;
+ mode_t saved_umask;
tmppath = g_malloc0 (strlen (path) + 10);
memcpy (tmppath, path, strlen (path));
strcat (tmppath, ".XXXXXX");
+ /* Only readable by root */
+ saved_umask = umask (S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+
errno = 0;
fd = mkstemp (tmppath);
if (fd < 0) {
@@ -158,17 +162,6 @@ write_secret_file (const char *path,
goto out;
}
- /* Only readable by root */
- errno = 0;
- if (fchmod (fd, S_IRUSR | S_IWUSR)) {
- close (fd);
- unlink (tmppath);
- g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
- "Could not set permissions for temporary file '%s': %d",
- path, errno);
- goto out;
- }
-
errno = 0;
written = write (fd, data, len);
if (written != len) {
@@ -193,6 +186,7 @@ write_secret_file (const char *path,
success = TRUE;
out:
+ umask (saved_umask);
g_free (tmppath);
return success;
}