terminal-util: reset access mode in vt_restore(), too
Only changing ownership back to root is not enough we also need to change the access mode, otherwise the user might have set 666 first, and thus allow everyone access before and after the chown().
This commit is contained in:
@@ -1291,8 +1291,7 @@ int vt_restore(int fd) {
|
||||
};
|
||||
int r, q = 0;
|
||||
|
||||
r = ioctl(fd, KDSETMODE, KD_TEXT);
|
||||
if (r < 0)
|
||||
if (ioctl(fd, KDSETMODE, KD_TEXT) < 0)
|
||||
q = log_debug_errno(errno, "Failed to set VT in text mode, ignoring: %m");
|
||||
|
||||
r = vt_reset_keyboard(fd);
|
||||
@@ -1302,18 +1301,17 @@ int vt_restore(int fd) {
|
||||
q = r;
|
||||
}
|
||||
|
||||
r = ioctl(fd, VT_SETMODE, &mode);
|
||||
if (r < 0) {
|
||||
if (ioctl(fd, VT_SETMODE, &mode) < 0) {
|
||||
log_debug_errno(errno, "Failed to set VT_AUTO mode, ignoring: %m");
|
||||
if (q >= 0)
|
||||
q = -errno;
|
||||
}
|
||||
|
||||
r = fchown(fd, 0, (gid_t) -1);
|
||||
r = fchmod_and_chown(fd, TTY_MODE, 0, (gid_t) -1);
|
||||
if (r < 0) {
|
||||
log_debug_errno(errno, "Failed to chown VT, ignoring: %m");
|
||||
log_debug_errno(r, "Failed to chmod()/chown() VT, ignoring: %m");
|
||||
if (q >= 0)
|
||||
q = -errno;
|
||||
q = r;
|
||||
}
|
||||
|
||||
return q;
|
||||
|
||||
@@ -163,3 +163,6 @@ int vt_restore(int fd);
|
||||
int vt_release(int fd, bool restore_vt);
|
||||
|
||||
void get_log_colors(int priority, const char **on, const char **off, const char **highlight);
|
||||
|
||||
/* This assumes there is a 'tty' group */
|
||||
#define TTY_MODE 0620
|
||||
|
||||
Reference in New Issue
Block a user