files: warn the root user when all the write bits are missing

Root has carte blanche to both read unreadable files and write
unwritable files -- the file system does not prevent this.  So,
alert root when opening a file that is intended to be read-only.

This fulfills https://savannah.gnu.org/bugs/?58685.
Requested-by: Marius Bakke <mbakke@fastmail.com>
This commit is contained in:
Benno Schulenberg 2020-07-01 18:47:14 +02:00
parent d18cfb26cd
commit 180a53cc0c

View File

@ -401,6 +401,10 @@ bool open_buffer(const char *filename, bool new_one)
free(realname);
return FALSE;
}
#else
if (new_one && !(fileinfo.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) &&
geteuid() == ROOT_UID)
statusline(ALERT, _("%s is meant to be read-only"), realname);
#endif
}