+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.
#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;
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);
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);
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);
/* 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