--- xc-old/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c.orig 2003-12-01 12:10:02.000000000 +1100 +++ xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c 2003-12-01 13:15:10.312671680 +1100 @@ -35,6 +35,8 @@ #include "xf86_OSlib.h" #include "lnx.h" +#include + #ifdef USE_DEV_FB extern char *getenv(const char *); #include @@ -45,13 +47,44 @@ static int VTnum = -1; static int activeVT = -1; +int vtPermSave[4]; +char vtname[11]; + +int saveVtPerms(void) +{ + /* We need to use stat to get permissions */ + struct stat svtp; + + /* Do them numerically ordered, hard coded tty0 first */ + if ( stat ("/dev/tty0", &svtp) != 0 ) + return 0; + vtPermSave[0] = (int)svtp.st_uid; + vtPermSave[1] = (int)svtp.st_gid; + + /* Now check the console we are dealing with. */ + if ( stat (vtname, &svtp) != 0 ) + return 0; + vtPermSave[2] = (int)svtp.st_uid; + vtPermSave[3] = (int)svtp.st_gid; + + return 1; +} + +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]); + + return; +} + void xf86OpenConsole(void) { int i, fd = -1; int result; struct vt_mode VT; - char vtname[11]; struct vt_stat vts; MessageType from = X_PROBED; #ifdef USE_DEV_FB @@ -124,6 +157,14 @@ xf86Info.vtno, strerror(errno)); } + /* + * grab the vt ownership before we overwrite it + * hard coded /dev/tty0 into this function aswell for below + */ + if (!saveVtPerms()){ + xf86Msg(X_WARNING, "xf86OpenConsole: Couldnt save owenership of vt"); + } + /* change ownership of the vt */ chown(vtname, getuid(), getgid()); @@ -247,6 +289,9 @@ activeVT = -1; } close(xf86Info.consoleFd); /* make the vt-manager happy */ + + restoreVtPerms(); /* restore the permissions */ + return; }