1 diff -urN XFree86-4.1.0.orig/xc/config/cf/Server.tmpl XFree86-4.1.0/xc/config/cf/Server.tmpl
2 --- XFree86-4.1.0.orig/xc/config/cf/Server.tmpl Fri Apr 20 17:51:15 2001
3 +++ XFree86-4.1.0/xc/config/cf/Server.tmpl Sun Jun 17 20:17:24 2001
6 #define MakeDllModules NO
8 +#ifndef XserverNeedsSetUID
9 +#define XserverNeedsSetUID NO
11 +#ifndef UseXserverWrapper
12 +#define UseXserverWrapper XserverNeedsSetUID
14 #ifndef InstallServerSetUID
15 -#define InstallServerSetUID NO
16 +#define InstallServerSetUID (XserverNeedsSetUID && !UseXserverWrapper)
20 --- XFree86-4.3.0/xc/config/cf/xf86site.def.orig Wed May 14 16:38:12 2003
21 +++ XFree86-4.3.0/xc/config/cf/xf86site.def Wed May 14 16:40:08 2003
26 - * If you only run the X server under xdm the X servers don't need to be
27 - * installed SetUID, and you may comment out the lines below. If you run
28 - * the servers by hand (with xinit or startx), then they do need to be
29 - * installed SetUID on most platforms.
30 + * The X servers need to run as root on most OSs. We're now using a
31 + * wrapper in that case, but we still need to make it known that the
32 + * servers need SetUID. When only using xdm, this (and the wrapper)
33 + * are not required. Disabling this automatically disables use of the
36 - * Consult your system administrator before making the X server setuid.
37 + * If you're only starting the Xservers with xdm set this to NO
39 -#define InstallXserverSetUID NO
40 +#define XserverNeedsSetUID NO
44 --- XFree86-4.1.0.orig/xc/config/cf/xfree86.cf Sun Jun 17 19:42:08 2001
45 +++ XFree86-4.1.0/xc/config/cf/xfree86.cf Sun Jun 17 20:17:24 2001
50 - * The default is to install the X servers setuid-root on most OSs.
51 - * It the servers are only started by xdm, they should not be setuid-root.
52 + * The X servers need to run as root on most OSs. We're now using a
53 + * wrapper in that case, but we still need to make it known that the
54 + * servers need SetUID. When only using xdm, this (and the wrapper)
55 + * are not required. Disabling this automatically disables use of the
58 #if !defined(i386MachArchitecture) && !defined(OS2Architecture)
59 -# ifndef InstallXserverSetUID
60 -# define InstallXserverSetUID YES
61 +# ifndef XserverNeedsSetUID
62 +# define XserverNeedsSetUID YES
66 diff -urN XFree86-4.1.0.orig/xc/programs/Xserver/Imakefile XFree86-4.1.0/xc/programs/Xserver/Imakefile
67 --- XFree86-4.1.0.orig/xc/programs/Xserver/Imakefile Fri May 18 19:48:30 2001
68 +++ XFree86-4.1.0/xc/programs/Xserver/Imakefile Sun Jun 17 20:17:24 2001
71 XCOMM $XFree86: xc/programs/Xserver/Imakefile,v 3.229 2001/05/18 17:48:30 torrey Exp $
73 -#ifndef InstallXserverSetUID
74 -#define InstallXserverSetUID NO
76 -#define InstallServerSetUID InstallXserverSetUID
78 #include <Server.tmpl>
81 @@ -1068,6 +1063,11 @@
82 $(XNESTLIBS) $(LOADABLEEXTS) $(LIBCWRAPPER),$(XNESTSYSLIBS))
83 #endif /* XnestServer */
86 +#if UseXserverWrapper
87 +SetUIDProgramTarget(Xwrapper,os/wrapper.o,NullParameter,$(PAMLIBS),NullParameter)
88 +InstallProgramWithFlags(Xwrapper,$(BINDIR),$(INSTUIDFLAGS))
93 diff -urN XFree86-4.1.0.orig/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c XFree86-4.1.0/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c
94 --- XFree86-4.1.0.orig/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c Tue Nov 14 22:59:24 2000
95 +++ XFree86-4.1.0/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c Sun Jun 17 20:17:24 2001
97 /* check if we're run with euid==0 */
100 - FatalError("xf86OpenConsole: Server must be suid root\n");
101 + FatalError("xf86OpenConsole: Server must be running with root "
103 + "You should be using Xwrapper to start the server or xdm.\n"
104 + "We strongly advise against making the server SUID root!\n");
108 diff -urN XFree86-4.1.0.orig/xc/programs/Xserver/os/Imakefile XFree86-4.1.0/xc/programs/Xserver/os/Imakefile
109 --- XFree86-4.1.0.orig/xc/programs/Xserver/os/Imakefile Mon Apr 23 18:17:12 2001
110 +++ XFree86-4.1.0/xc/programs/Xserver/os/Imakefile Sun Jun 17 20:18:35 2001
112 INCLUDES = -I. -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) \
113 -I$(SERVERSRC)/Xext -I$(FONTINCSRC) \
114 -I$(TOP)/lib/Xau -I../lbx Krb5Includes
115 + EXTRA_DEFINES = -DUSE_PAM
116 DEPEND_DEFINES = $(DBM_DEFINES) $(XDMCP_DEFINES) $(EXT_DEFINES) \
117 $(TRANS_INCLUDES) $(CONNECTION_FLAGS) DependDefines
118 LINTLIBS = ../dix/llib-ldix.ln
120 cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c
122 SpecialCObjectRule(oscolor,$(ICONFIGFILES),$(DBM_DEFINES))
125 +#if UseXserverWrapper
126 +AllTarget(wrapper.o)
128 + WRAPPER_DEFINES = -DXSERVER_PATH=\"/etc/X11/X\"
130 +SpecialCObjectRule(wrapper,NullParameter,$(WRAPPER_DEFINES))
134 diff -urN XFree86-4.1.0.orig/xc/programs/Xserver/os/wrapper.c XFree86-4.1.0/xc/programs/Xserver/os/wrapper.c
135 --- XFree86-4.1.0.orig/xc/programs/Xserver/os/wrapper.c Thu Jan 1 01:00:00 1970
136 +++ XFree86-4.1.0/xc/programs/Xserver/os/wrapper.c Sun Jun 17 20:17:24 2001
139 + * X server wrapper.
141 + * This wrapper makes some sanity checks on the command line arguments
142 + * and environment variables when run with euid == 0 && euid != uid.
143 + * If the checks fail, the wrapper exits with a message.
144 + * If they succeed, it exec's the Xserver.
148 + * Copyright (c) 1998 by The XFree86 Project, Inc. All Rights Reserved.
150 + * Permission is hereby granted, free of charge, to any person obtaining
151 + * a copy of this software and associated documentation files (the
152 + * "Software"), to deal in the Software without restriction, including
153 + * without limitation the rights to use, copy, modify, merge, publish,
154 + * distribute, sublicense, and/or sell copies of the Software, and to
155 + * permit persons to whom the Software is furnished to do so, subject
156 + * to the following conditions:
158 + * The above copyright notice and this permission notice shall be included
159 + * in all copies or substantial portions of the Software.
161 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
162 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
163 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
164 + * IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES
165 + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
166 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
167 + * OR OTHER DEALINGS IN THE SOFTWARE.
169 + * Except as contained in this notice, the name of the XFree86 Project
170 + * shall not be used in advertising or otherwise to promote the sale,
171 + * use or other dealings in this Software without prior written
172 + * authorization from the XFree86 Project.
175 +/* $XFree86: xc/programs/Xserver/os/wrapper.c,v 1.1.2.5 1998/02/27 15:28:59 dawes Exp $ */
177 +/* This is normally set in the Imakefile */
178 +#ifndef XSERVER_PATH
179 +#define XSERVER_PATH "/etc/X11/X"
187 +#include <sys/types.h>
189 +#include <security/pam_appl.h>
190 +#include <security/pam_misc.h>
192 +#endif /* USE_PAM */
194 +/* Neither of these should be required for XFree86 3.3.2 */
195 +#ifndef REJECT_CONFIG
196 +#define REJECT_CONFIG 0
198 +#ifndef REJECT_XKBDIR
199 +#define REJECT_XKBDIR 0
202 +/* Consider LD* variables insecure ? */
203 +#ifndef REMOVE_ENV_LD
204 +#define REMOVE_ENV_LD 1
207 +/* Remove long environment variables? */
208 +#ifndef REMOVE_LONG_ENV
209 +#define REMOVE_LONG_ENV 1
212 +/* Check args and env only if running setuid (euid == 0 && euid != uid) ? */
214 +#define CHECK_EUID 1
218 + * Maybe the locale can be faked to make isprint(3) report that everything
219 + * is printable? Avoid it by default.
222 +#define USE_ISPRINT 0
225 +#define MAX_ARG_LENGTH 128
226 +#define MAX_ENV_LENGTH 256
227 +#define MAX_ENV_PATH_LENGTH 2048
231 +#define checkPrintable(c) isprint(c)
233 +#define checkPrintable(c) (((c) & 0x7f) >= 0x20 && ((c) & 0x7f) != 0x7f)
246 +#endif /* USE_PAM */
250 + "\nIf the arguments used are valid, and have been rejected incorrectly\n" \
251 + "please send details of the arguments and why they are valid to\n" \
252 + "XFree86@XFree86.org. In the meantime, you can start the Xserver as\n" \
253 + "the \"super user\" (root).\n"
256 + "\nIf the environment is valid, and have been rejected incorrectly\n" \
257 + "please send details of the environment and why it is valid to\n" \
258 + "XFree86@XFree86.org. In the meantime, you can start the Xserver as\n" \
259 + "the \"super user\" (root).\n"
262 +static struct pam_conv conv = {
266 +#endif /* USE_PAM */
270 +main(int argc, char **argv, char **envp)
272 + enum BadCode bad = NotBad;
276 + pam_handle_t *pamh = NULL;
280 + pw = getpwuid(getuid());
282 + bad = InternalError;
286 + retval = pam_start("xserver", pw->pw_name, &conv, &pamh);
287 + if (retval != PAM_SUCCESS)
292 + retval = pam_authenticate(pamh, 0);
293 + if (retval != PAM_SUCCESS) {
294 + pam_end(pamh, retval);
295 + bad = PamAuthFailed;
300 + retval = pam_acct_mgmt(pamh, 0);
301 + if (retval != PAM_SUCCESS) {
302 + pam_end(pamh, retval);
303 + bad = PamAuthFailed;
307 + /* this is not a session, so do not do session management */
309 + if (!bad) pam_end(pamh, PAM_SUCCESS);
310 +#endif /* USE_PAM */
313 + if (!bad && geteuid() == 0 && getuid() != geteuid()) {
317 + /* Check each argv[] */
318 + for (i = 1; i < argc; i++) {
320 + /* Check for known bad arguments */
322 + if (strcmp(argv[i], "-config") == 0) {
328 + if (strcmp(argv[i], "-xkbdir") == 0) {
333 + if (strlen(argv[i]) > MAX_ARG_LENGTH) {
339 + if (checkPrintable(*a) == 0) {
340 + bad = UnprintableArg;
348 + /* Check each envp[] */
350 + for (i = 0; envp[i]; i++) {
352 + /* Check for bad environment variables and values */
354 + while (envp[i] && (strncmp(envp[i], "LD", 2) == 0)) {
355 + for (j = i; envp[j]; j++) {
356 + envp[j] = envp[j+1];
360 + if (envp[i] && (strlen(envp[i]) > MAX_ENV_LENGTH)) {
362 + for (j = i; envp[j]; j++) {
363 + envp[j] = envp[j+1];
370 + eq = strchr(envp[i], '=');
373 + len = eq - envp[i];
374 + e = malloc(len + 1);
376 + bad = InternalError;
379 + strncpy(e, envp[i], len);
382 + (strcmp(e + len - 4, "PATH") == 0 ||
383 + strcmp(e, "TERMCAP") == 0)) {
384 + if (strlen(envp[i]) > MAX_ENV_PATH_LENGTH) {
400 + execve(XSERVER_PATH, argv, envp);
401 + fprintf(stderr, "execve failed for %s (errno %d)\n", XSERVER_PATH,
405 + fprintf(stderr, "Command line argument number %d is unsafe\n", i);
406 + fprintf(stderr, ARGMSG);
409 + fprintf(stderr, "Command line argument number %d is too long\n", i);
410 + fprintf(stderr, ARGMSG);
412 + case UnprintableArg:
413 + fprintf(stderr, "Command line argument number %d contains unprintable"
414 + " characters\n", i);
415 + fprintf(stderr, ARGMSG);
418 + fprintf(stderr, "Environment variable `%s' is too long\n", e);
419 + fprintf(stderr, ENVMSG);
421 + case InternalError:
422 + fprintf(stderr, "Internal Error\n");
426 + fprintf(stderr, "Authentication System Failure, "
427 + "missing or mangled PAM configuration file or module?\n");
429 + case PamAuthFailed:
430 + fprintf(stderr, "PAM authentication failed\n");
434 + fprintf(stderr, "Unknown error\n");
435 + fprintf(stderr, ARGMSG);
436 + fprintf(stderr, ENVMSG);
442 diff -urN XFree86-4.1.0.orig/xc/programs/xinit/xinit.c XFree86-4.1.0/xc/programs/xinit/xinit.c
443 --- XFree86-4.1.0.orig/xc/programs/xinit/xinit.c Mon Apr 16 08:51:46 2001
444 +++ XFree86-4.1.0/xc/programs/xinit/xinit.c Sun Jun 17 20:17:24 2001
449 +char *default_wrapper = BINDIR "/Xwrapper";
450 char *default_server = "X";
451 char *default_display = ":0"; /* choose most efficient */
456 (**argv != '/' && **argv != '.')) {
457 - *sptr++ = default_server;
458 + if (access(default_wrapper, X_OK) == 0)
459 + *sptr++ = default_wrapper;
461 + *sptr++ = default_server;
463 (**argv != '/' && **argv != '\\' && **argv != '.' &&
464 !(isalpha(**argv) && (*argv)[1]==':'))) {
465 --- XFree86-4.2.0/xc/programs/xinit/startx.cpp.orig Fri Nov 30 21:57:48 2001
466 +++ XFree86-4.2.0/xc/programs/xinit/startx.cpp Sun Mar 3 12:52:13 2002
468 sysclientrc=XINITDIR/xinitrc
469 sysserverrc=XINITDIR/xserverrc
470 defaultclient=BINDIR/xterm
471 -defaultserver=BINDIR/X
472 +defaultserver=BINDIR/Xwrapper