commit 3d411188f6dcc5ab18cd2218de566e0fdd593a55
parent d5b1c7c5bf4db1ab739cd30345f7138f41b6dfcc
Author: Chris Allegretta <chrisa@asty.org>
Date: Mon, 7 Feb 2011 02:06:20 +0000
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
Diffstat:
3 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -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.
diff --git a/src/files.c b/src/files.c
@@ -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);
@@ -1628,7 +1647,9 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
root, since it's likely to fail! */
if (geteuid() == NANO_ROOT_UID && fchown(backup_fd,
openfile->current_stat->st_uid, openfile->current_stat->st_gid) == -1
- && !ISSET(INSECURE_BACKUP)) {
+ && !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
diff --git a/src/winio.c b/src/winio.c
@@ -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