Explicitly set the file mode of I/O log files so the mode is not

affected by the invoking user's umask.
This commit is contained in:
Todd C. Miller
2017-03-21 13:54:27 -06:00
parent 8d57491dc1
commit 1bd90d8fff
2 changed files with 16 additions and 3 deletions

View File

@@ -53,6 +53,7 @@ sudo_mkdir_parents(char *path, uid_t uid, gid_t gid, mode_t mode, bool quiet)
if (mkdir(path, mode) == 0) {
if (uid != (uid_t)-1 && gid != (gid_t)-1)
ignore_result(chown(path, uid, gid));
ignore_result(chmod(path, mode));
} else {
if (errno != EEXIST) {
if (!quiet)
@@ -65,7 +66,14 @@ sudo_mkdir_parents(char *path, uid_t uid, gid_t gid, mode_t mode, bool quiet)
sudo_warn(U_("unable to stat %s"), path);
goto bad;
}
if (!S_ISDIR(sb.st_mode)) {
if (S_ISDIR(sb.st_mode)) {
if (uid != (uid_t)-1 && gid != (gid_t)-1) {
if (sb.st_uid != uid || sb.st_gid != uid)
ignore_result(chown(path, uid, uid));
}
if ((sb.st_mode & ALLPERMS) != mode)
ignore_result(chmod(path, mode));
} else {
if (!quiet)
sudo_warnx(U_("%s exists but is not a directory (0%o)"),
path, (unsigned int) sb.st_mode);