Fix: SE022 Problem: X11 port fails to open DISPLAY if game is installed setuid and if the X server is using token based authentication. This is because it needs to read $HOME/.Xauthority to get the token and this file is normally only readable by the user. The solution is to revert to the UID of the real user while we open the DISPLAY and then back to the effective UID afterwards. Compatible with: Slash'EM 0.0.4E7 through 0.0.5E6F1, and probably earlier NetHack 3.2.2 Author: Michael Hohmuth, hohmuth@inf.tu-dresden.de J. Ali Harlow, ali@avrc.city.ac.uk Date: 8 Nov 1999 *** win/X11/winX.c.orig Mon Nov 1 12:48:07 1999 --- win/X11/winX.c Mon Nov 8 16:53:45 1999 *************** *** 910,915 **** --- 910,916 ---- int i; Cardinal num_args; Arg args[4]; + uid_t gamesuid=geteuid(); /* Init windows to nothing. */ for (i = 0; i < MAX_WINDOWS; i++) *************** *** 919,924 **** --- 920,938 ---- num_args = 0; XtSetArg(args[num_args], XtNallowShellResize, True); num_args++; + + /* + * Shamelessly stolen from Qt interface by Ali ... + * + * Michael Hohmuth ... + * + * As the game runs setuid games, it must seteuid(getuid()) before + * calling XOpenDisplay(), and reset the euid afterwards. + * Otherwise, it can't read the $HOME/.Xauthority file and whines about + * not being able to open the X display (if a magic-cookie + * authorization mechanism is being used). + */ + seteuid(getuid()); toplevel = XtAppInitialize( &app_context, "NetHack", /* application class */ *************** *** 926,931 **** --- 940,946 ---- argcp, (String *)argv, /* command line args */ (String *)0, /* fallback resources */ (ArgList)args, num_args); + seteuid(gamesuid); XtOverrideTranslations(toplevel, XtParseTranslationTable("WM_PROTOCOLS: X11_hangup()"));