From f277225d33d93d228ce1c953e050331c501e646b Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 6 Jun 2010 22:58:46 +0100 Subject: 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. --- storage_xml.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'storage_xml.c') 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." ); -- cgit v1.2.3