From d225230148b3cdab3b32fce3abee26b818d4bab0 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Tue, 18 Aug 2009 12:15:32 -0700 Subject: [PATCH] xfree86/linux: don't change VT perms unless we're running as root In non-setuid root installations, we shouldn't try to adjust VT/tty ownership. It will fail, and shouldn't be necessary anyway (since startup scripts or PAM should be handling perms for us in that case). Signed-off-by: Jesse Barnes --- hw/xfree86/os-support/linux/lnx_init.c | 36 ++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c index a49086b37..64030072f 100644 --- a/hw/xfree86/os-support/linux/lnx_init.c +++ b/hw/xfree86/os-support/linux/lnx_init.c @@ -74,9 +74,11 @@ saveVtPerms(void) static void restoreVtPerms(void) { - /* Set the terminal permissions back to before we started. */ - chown("/dev/tty0", vtPermSave[0], vtPermSave[1]); - chown(vtname, vtPermSave[2], vtPermSave[3]); + if (geteuid() == 0) { + /* Set the terminal permissions back to before we started. */ + (void)chown("/dev/tty0", vtPermSave[0], vtPermSave[1]); + (void)chown(vtname, vtPermSave[2], vtPermSave[3]); + } } static void *console_handler; @@ -184,20 +186,22 @@ xf86OpenConsole(void) xf86Msg(X_WARNING, "xf86OpenConsole: Could not save ownership of VT\n"); - /* change ownership of the vt */ - if (chown(vtname, getuid(), getgid()) < 0) - xf86Msg(X_WARNING,"xf86OpenConsole: chown %s failed: %s\n", - vtname, strerror(errno)); + if (geteuid() == 0) { + /* change ownership of the vt */ + if (chown(vtname, getuid(), getgid()) < 0) + xf86Msg(X_WARNING,"xf86OpenConsole: chown %s failed: %s\n", + vtname, strerror(errno)); - /* - * the current VT device we're running on is not "console", we want - * to grab all consoles too - * - * Why is this needed?? - */ - if (chown("/dev/tty0", getuid(), getgid()) < 0) - xf86Msg(X_WARNING,"xf86OpenConsole: chown /dev/tty0 failed: %s\n", - strerror(errno)); + /* + * the current VT device we're running on is not + * "console", we want to grab all consoles too + * + * Why is this needed?? + */ + if (chown("/dev/tty0", getuid(), getgid()) < 0) + xf86Msg(X_WARNING,"xf86OpenConsole: chown /dev/tty0 failed: %s\n", + strerror(errno)); + } } /*