From 180a53cc0c59fcced2f610d4090c714d97f6f260 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 1 Jul 2020 18:47:14 +0200 Subject: [PATCH] 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 --- src/files.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/files.c b/src/files.c index c3b6c3e7..10bccd04 100644 --- a/src/files.c +++ b/src/files.c @@ -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 }