2011-02-06 Chris Allegretta <chrisa@asty.org>

* files.c (write_file) - Fix problems with writing the backup file (albeit interactively)
	  with new function prompt_failed_backupwrite(), allows more secure handling of problems
	  with failing to write the backup file compared to 'allow_insecure_backup'.
	* winio.c (edit_redraw): Removed unused variable



git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4526 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2011-02-07 02:06:20 +00:00
parent d5b1c7c5bf
commit 3d411188f6
3 changed files with 34 additions and 3 deletions

View File

@ -1,3 +1,9 @@
2011-02-06 Chris Allegretta <chrisa@asty.org>
* files.c (write_file) - Fix problems with writing the backup file (albeit interactively)
with new function prompt_failed_backupwrite(), allows more secure handling of problems
with failing to write the backup file compared to 'allow_insecure_backup'.
* winio.c (edit_redraw): Removed unused variable
2010-11-15 Chris Allegretta <chrisa@asty.org>
* Add a section to the FAQ about using nanorc on Win32 systems.

View File

@ -1366,6 +1366,23 @@ bool check_operating_dir(const char *currpath, bool allow_tabcomp)
#endif
#ifndef NANO_TINY
/* Although this sucks, it sucks less than having a single 'my system is messed up
* and I'm blanket allowing insecure file writing operations.
*/
int prompt_failed_backupwrite(const char *filename)
{
static int i;
static char *prevfile = NULL; /* What was the laast file we were paased so we don't keep asking this?
though maybe we should.... */
if (prevfile == NULL || strcmp(filename, prevfile)) {
i = do_yesno_prompt(FALSE,
_("Failed to write backup file, continue saving? (Say N if unsure) "));
prevfile = mallocstrcpy(prevfile, filename);
}
return i;
}
void init_backup_dir(void)
{
char *full_backup_dir;
@ -1600,6 +1617,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
file with O_CREAT and O_EXCL. If it succeeds, we
have a file descriptor to a new backup file. */
if (unlink(backupname) < 0 && errno != ENOENT && !ISSET(INSECURE_BACKUP)) {
if (prompt_failed_backupwrite(backupname))
goto skip_backup;
statusbar(_("Error writing backup file %s: %s"), backupname,
strerror(errno));
free(backupname);
@ -1629,6 +1648,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
if (geteuid() == NANO_ROOT_UID && fchown(backup_fd,
openfile->current_stat->st_uid, openfile->current_stat->st_gid) == -1
&& !ISSET(INSECURE_BACKUP)) {
if (prompt_failed_backupwrite(backupname))
goto skip_backup;
statusbar(_("Error writing backup file %s: %s"), backupname,
strerror(errno));
free(backupname);
@ -1636,7 +1657,10 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
goto cleanup_and_exit;
}
if (fchmod(backup_fd, openfile->current_stat->st_mode) == -1 && !ISSET(INSECURE_BACKUP)) {
if (fchmod(backup_fd, openfile->current_stat->st_mode) == -1
&& !ISSET(INSECURE_BACKUP)) {
if (prompt_failed_backupwrite(backupname))
goto skip_backup;
statusbar(_("Error writing backup file %s: %s"), backupname,
strerror(errno));
free(backupname);
@ -1664,6 +1688,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
/* And set its metadata. */
if (utime(backupname, &filetime) == -1 && !ISSET(INSECURE_BACKUP)) {
if (prompt_failed_backupwrite(backupname))
goto skip_backup;
statusbar(_("Error writing backup file %s: %s"), backupname,
strerror(errno));
/* If we can't write to the backup, DONT go on, since

View File

@ -3125,7 +3125,6 @@ void edit_redraw(filestruct *old_current, size_t pww_save)
old_current->lineno, openfile->edittop->lineno);
#endif
filestruct *old_edittop = openfile->edittop;
ssize_t nlines;
#ifndef NANO_TINY
/* If the mark is on, update all the lines between old_current