files: ignore only EPERM when fchmod() or fchown() fails

While ignoring permission errors from fchmod() and fchown() is okay
(since normal users are not always privileged to make such changes),
ignoring also more serious errors (like EIO) is not ideal.

Signed-off-by: Michalis Kokologiannakis <michalis@mpi-sws.org>
master
Michalis Kokologiannakis 2020-07-28 11:05:52 +03:00 committed by Benno Schulenberg
parent 59bdce9503
commit d0ad1e42d9
1 changed files with 10 additions and 4 deletions

View File

@ -1619,14 +1619,20 @@ bool make_backup_of(char *realname)
goto problem;
/* Try to change owner and group to those of the original file;
* ignore errors, as a normal user cannot change the owner. */
IGNORE_CALL_RESULT(fchown(descriptor, openfile->statinfo->st_uid,
openfile->statinfo->st_gid));
* ignore permission errors, as a normal user cannot change the owner. */
if (fchown(descriptor, openfile->statinfo->st_uid,
openfile->statinfo->st_gid) < 0 && errno != EPERM) {
fclose(backup_file);
goto problem;
}
/* Set the backup's permissions to those of the original file.
* It is not a security issue if this fails, as we have created
* the file with just read and write permission for the owner. */
IGNORE_CALL_RESULT(fchmod(descriptor, openfile->statinfo->st_mode));
if (fchmod(descriptor, openfile->statinfo->st_mode) < 0 && errno != EPERM) {
fclose(backup_file);
goto problem;
}
original = fopen(realname, "rb");