From: kink Date: Mon, 14 Oct 2002 22:02:46 +0000 (+0000) Subject: Forwardporting safer abook/prefs saving from stable X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=45df3062c96fb474ea804b444da1857782c999aa;p=squirrelmail.git Forwardporting safer abook/prefs saving from stable git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3849 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/abook_local_file.php b/functions/abook_local_file.php index 9f7acf7a..ca611932 100644 --- a/functions/abook_local_file.php +++ b/functions/abook_local_file.php @@ -135,9 +135,9 @@ class abook_local_file extends addressbook_backend { * NOTE! Previous locks are broken by this function */ function overwrite(&$rows) { $this->unlock(); - $newfh = @fopen($this->filename, 'w'); + $newfh = @fopen($this->filename .'.tmp', 'w'); if(!$newfh) { - return $this->set_error("$file: " . _("Open failed")); + return $this->set_error($this->filename .'.tmp: '. _("Open failed")); } for($i = 0 ; $i < sizeof($rows) ; $i++) { @@ -150,6 +150,8 @@ class abook_local_file extends addressbook_backend { } fclose($newfh); + copy( $this->filename .'.tmp' , $this->filename); + unlink( $this->filename .'.tmp'); $this->unlock(); $this->open(true); return true; @@ -376,4 +378,4 @@ class abook_local_file extends addressbook_backend { } } /* End of class abook_local_file */ -?> \ No newline at end of file +?> diff --git a/functions/file_prefs.php b/functions/file_prefs.php index 073b366a..8dacc32a 100644 --- a/functions/file_prefs.php +++ b/functions/file_prefs.php @@ -106,10 +106,10 @@ function savePrefValues($data_dir, $username) { $filename = getHashedFile($username, $data_dir, "$username.pref"); /* Open the file for writing, or else display an error to the user. */ - if(!$file = @fopen($filename, 'w')) + if(!$file = @fopen($filename.'.tmp', 'w')) { include_once(SM_PATH . 'functions/display_messages.php'); - logout_error( sprintf( _("Preference file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename) ); + logout_error( sprintf( _("Preference file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename.'.tmp') ); exit; } @@ -119,6 +119,8 @@ function savePrefValues($data_dir, $username) { } } fclose($file); + copy($filename.'.tmp', $filename); + unlink($filename.'.tmp'); chmod($filename, 0600); } @@ -208,14 +210,16 @@ function checkForPrefs($data_dir, $username, $filename = '') { function setSig($data_dir, $username, $number, $value) { $filename = getHashedFile($username, $data_dir, "$username.si$number"); /* Open the file for writing, or else display an error to the user. */ - if(!$file = @fopen($filename, 'w')) + if(!$file = @fopen($filename.'.tmp', 'w')) { include_once(SM_PATH . '/functions/display_messages.php' ); - logout_error( sprintf( _("Signature file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename) ); + logout_error( sprintf( _("Signature file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename.'.tmp') ); exit; } fwrite($file, $value); fclose($file); + copy($filename.'.tmp',$filename); + unlink($filename.'.tmp'); } /**