diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-06-06 22:58:46 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-06-06 22:58:46 +0100 |
commit | f277225d33d93d228ce1c953e050331c501e646b (patch) | |
tree | e01a20be49e5b76419aac4e3c68d485e2b89d221 /storage_xml.c | |
parent | 3dc6d86076dbea16c313bb87aa2f37166f289a8e (diff) |
Use mkstemp() instead of just a tilde-file when writing new configs to a
temporary file. This solves hard-to-debug issues where for example the
user hand-edited his configs as root and left a root-owned user.xml~ file
behind.
Diffstat (limited to 'storage_xml.c')
-rw-r--r-- | storage_xml.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/storage_xml.c b/storage_xml.c index 8c524ca9..071fcd11 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -403,8 +403,8 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) if( !overwrite && g_access( path, F_OK ) == 0 ) return STORAGE_ALREADY_EXISTS; - strcat( path, "~" ); - if( ( fd = open( path, O_WRONLY | O_CREAT | O_TRUNC, 0600 ) ) < 0 ) + strcat( path, ".XXXXXX" ); + if( ( fd = mkstemp( path ) ) < 0 ) { irc_usermsg( irc, "Error while opening configuration file." ); return STORAGE_OTHER_ERROR; @@ -498,7 +498,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) fsync( fd ); close( fd ); - path2 = g_strndup( path, strlen( path ) - 1 ); + path2 = g_strndup( path, strlen( path ) - 7 ); if( rename( path, path2 ) != 0 ) { irc_usermsg( irc, "Error while renaming temporary configuration file." ); |