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 diff -urN XFree86-4.1.0.orig/xc/config/cf/xf86site.def XFree86-4.1.0/xc/config/cf/xf86site.def
21 --- XFree86-4.1.0.orig/xc/config/cf/xf86site.def Sun Jun 17 19:42:08 2001
22 +++ XFree86-4.1.0/xc/config/cf/xf86site.def Sun Jun 17 20:17:24 2001
27 - * If you only run the X server under xdm the X servers don't need to be
28 - * installed SetUID, and you may comment out the lines below. If you run
29 - * the servers by hand (with xinit or startx), then they do need to be
30 - * installed SetUID on most OSs.
31 - * Consult your system administrator before making the X server setuid.
32 + * The X servers need to run as root on most OSs. We're now using a
33 + * wrapper in that case, but we still need to make it known that the
34 + * servers need SetUID. When only using xdm, this (and the wrapper)
35 + * are not required. Disabling this automatically disables use of the
38 -#define InstallXserverSetUID NO
39 + * If you're only starting the Xservers with xdm set this to NO
41 +#define XserverNeedsSetUID NO
45 diff -urN XFree86-4.1.0.orig/xc/config/cf/xfree86.cf XFree86-4.1.0/xc/config/cf/xfree86.cf
46 --- XFree86-4.1.0.orig/xc/config/cf/xfree86.cf Sun Jun 17 19:42:08 2001
47 +++ XFree86-4.1.0/xc/config/cf/xfree86.cf Sun Jun 17 20:17:24 2001
52 - * The default is to install the X servers setuid-root on most OSs.
53 - * It the servers are only started by xdm, they should not be setuid-root.
54 + * The X servers need to run as root on most OSs. We're now using a
55 + * wrapper in that case, but we still need to make it known that the
56 + * servers need SetUID. When only using xdm, this (and the wrapper)
57 + * are not required. Disabling this automatically disables use of the
60 #if !defined(i386MachArchitecture) && !defined(OS2Architecture)
61 -# ifndef InstallXserverSetUID
62 -# define InstallXserverSetUID YES
63 +# ifndef XserverNeedsSetUID
64 +# define XserverNeedsSetUID YES
68 diff -urN XFree86-4.1.0.orig/xc/programs/Xserver/Imakefile XFree86-4.1.0/xc/programs/Xserver/Imakefile
69 --- XFree86-4.1.0.orig/xc/programs/Xserver/Imakefile Fri May 18 19:48:30 2001
70 +++ XFree86-4.1.0/xc/programs/Xserver/Imakefile Sun Jun 17 20:17:24 2001
73 XCOMM $XFree86: xc/programs/Xserver/Imakefile,v 3.229 2001/05/18 17:48:30 torrey Exp $
75 -#ifndef InstallXserverSetUID
76 -#define InstallXserverSetUID NO
78 -#define InstallServerSetUID InstallXserverSetUID
80 #include <Server.tmpl>
83 @@ -1068,6 +1063,11 @@
84 $(XNESTLIBS) $(LOADABLEEXTS) $(LIBCWRAPPER),$(XNESTSYSLIBS))
85 #endif /* XnestServer */
88 +#if UseXserverWrapper
89 +SetUIDProgramTarget(Xwrapper,os/wrapper.o,NullParameter,$(PAMLIBS),NullParameter)
90 +InstallProgramWithFlags(Xwrapper,$(BINDIR),$(INSTUIDFLAGS))
95 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
96 --- XFree86-4.1.0.orig/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c Tue Nov 14 22:59:24 2000
97 +++ XFree86-4.1.0/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c Sun Jun 17 20:17:24 2001
99 /* check if we're run with euid==0 */
102 - FatalError("xf86OpenConsole: Server must be suid root\n");
103 + FatalError("xf86OpenConsole: Server must be running with root "
105 + "You should be using Xwrapper to start the server or xdm.\n"
106 + "We strongly advise against making the server SUID root!\n");
110 diff -urN XFree86-4.1.0.orig/xc/programs/Xserver/os/Imakefile XFree86-4.1.0/xc/programs/Xserver/os/Imakefile
111 --- XFree86-4.1.0.orig/xc/programs/Xserver/os/Imakefile Mon Apr 23 18:17:12 2001
112 +++ XFree86-4.1.0/xc/programs/Xserver/os/Imakefile Sun Jun 17 20:18:35 2001
114 INCLUDES = -I. -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) \
115 -I$(SERVERSRC)/Xext -I$(FONTINCSRC) \
116 -I$(TOP)/lib/Xau -I../lbx Krb5Includes
117 + EXTRA_DEFINES = -DUSE_PAM
118 DEPEND_DEFINES = $(DBM_DEFINES) $(XDMCP_DEFINES) $(EXT_DEFINES) \
119 $(TRANS_INCLUDES) $(CONNECTION_FLAGS) DependDefines
120 LINTLIBS = ../dix/llib-ldix.ln
122 cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c
124 SpecialCObjectRule(oscolor,$(ICONFIGFILES),$(DBM_DEFINES))
127 +#if UseXserverWrapper
128 +AllTarget(wrapper.o)
130 + WRAPPER_DEFINES = -DXSERVER_PATH=\"/etc/X11/X\"
132 +SpecialCObjectRule(wrapper,NullParameter,$(WRAPPER_DEFINES))
136 diff -urN XFree86-4.1.0.orig/xc/programs/Xserver/os/wrapper.c XFree86-4.1.0/xc/programs/Xserver/os/wrapper.c
137 --- XFree86-4.1.0.orig/xc/programs/Xserver/os/wrapper.c Thu Jan 1 01:00:00 1970
138 +++ XFree86-4.1.0/xc/programs/Xserver/os/wrapper.c Sun Jun 17 20:17:24 2001
141 + * X server wrapper.
143 + * This wrapper makes some sanity checks on the command line arguments
144 + * and environment variables when run with euid == 0 && euid != uid.
145 + * If the checks fail, the wrapper exits with a message.
146 + * If they succeed, it exec's the Xserver.
150 + * Copyright (c) 1998 by The XFree86 Project, Inc. All Rights Reserved.
152 + * Permission is hereby granted, free of charge, to any person obtaining
153 + * a copy of this software and associated documentation files (the
154 + * "Software"), to deal in the Software without restriction, including
155 + * without limitation the rights to use, copy, modify, merge, publish,
156 + * distribute, sublicense, and/or sell copies of the Software, and to
157 + * permit persons to whom the Software is furnished to do so, subject
158 + * to the following conditions:
160 + * The above copyright notice and this permission notice shall be included
161 + * in all copies or substantial portions of the Software.
163 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
164 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
165 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
166 + * IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES
167 + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
168 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
169 + * OR OTHER DEALINGS IN THE SOFTWARE.
171 + * Except as contained in this notice, the name of the XFree86 Project
172 + * shall not be used in advertising or otherwise to promote the sale,
173 + * use or other dealings in this Software without prior written
174 + * authorization from the XFree86 Project.
177 +/* $XFree86: xc/programs/Xserver/os/wrapper.c,v 1.1.2.5 1998/02/27 15:28:59 dawes Exp $ */
179 +/* This is normally set in the Imakefile */
180 +#ifndef XSERVER_PATH
181 +#define XSERVER_PATH "/etc/X11/X"
189 +#include <sys/types.h>
191 +#include <security/pam_appl.h>
192 +#include <security/pam_misc.h>
194 +#endif /* USE_PAM */
196 +/* Neither of these should be required for XFree86 3.3.2 */
197 +#ifndef REJECT_CONFIG
198 +#define REJECT_CONFIG 0
200 +#ifndef REJECT_XKBDIR
201 +#define REJECT_XKBDIR 0
204 +/* Consider LD* variables insecure ? */
205 +#ifndef REMOVE_ENV_LD
206 +#define REMOVE_ENV_LD 1
209 +/* Remove long environment variables? */
210 +#ifndef REMOVE_LONG_ENV
211 +#define REMOVE_LONG_ENV 1
214 +/* Check args and env only if running setuid (euid == 0 && euid != uid) ? */
216 +#define CHECK_EUID 1
220 + * Maybe the locale can be faked to make isprint(3) report that everything
221 + * is printable? Avoid it by default.
224 +#define USE_ISPRINT 0
227 +#define MAX_ARG_LENGTH 128
228 +#define MAX_ENV_LENGTH 256
229 +#define MAX_ENV_PATH_LENGTH 2048
233 +#define checkPrintable(c) isprint(c)
235 +#define checkPrintable(c) (((c) & 0x7f) >= 0x20 && ((c) & 0x7f) != 0x7f)
248 +#endif /* USE_PAM */
252 + "\nIf the arguments used are valid, and have been rejected incorrectly\n" \
253 + "please send details of the arguments and why they are valid to\n" \
254 + "XFree86@XFree86.org. In the meantime, you can start the Xserver as\n" \
255 + "the \"super user\" (root).\n"
258 + "\nIf the environment is valid, and have been rejected incorrectly\n" \
259 + "please send details of the environment and why it is valid to\n" \
260 + "XFree86@XFree86.org. In the meantime, you can start the Xserver as\n" \
261 + "the \"super user\" (root).\n"
264 +static struct pam_conv conv = {
268 +#endif /* USE_PAM */
272 +main(int argc, char **argv, char **envp)
274 + enum BadCode bad = NotBad;
278 + pam_handle_t *pamh = NULL;
282 + pw = getpwuid(getuid());
284 + bad = InternalError;
288 + retval = pam_start("xserver", pw->pw_name, &conv, &pamh);
289 + if (retval != PAM_SUCCESS)
294 + retval = pam_authenticate(pamh, 0);
295 + if (retval != PAM_SUCCESS) {
296 + pam_end(pamh, retval);
297 + bad = PamAuthFailed;
302 + retval = pam_acct_mgmt(pamh, 0);
303 + if (retval != PAM_SUCCESS) {
304 + pam_end(pamh, retval);
305 + bad = PamAuthFailed;
309 + /* this is not a session, so do not do session management */
311 + if (!bad) pam_end(pamh, PAM_SUCCESS);
312 +#endif /* USE_PAM */
315 + if (!bad && geteuid() == 0 && getuid() != geteuid()) {
319 + /* Check each argv[] */
320 + for (i = 1; i < argc; i++) {
322 + /* Check for known bad arguments */
324 + if (strcmp(argv[i], "-config") == 0) {
330 + if (strcmp(argv[i], "-xkbdir") == 0) {
335 + if (strlen(argv[i]) > MAX_ARG_LENGTH) {
341 + if (checkPrintable(*a) == 0) {
342 + bad = UnprintableArg;
350 + /* Check each envp[] */
352 + for (i = 0; envp[i]; i++) {
354 + /* Check for bad environment variables and values */
356 + while (envp[i] && (strncmp(envp[i], "LD", 2) == 0)) {
357 + for (j = i; envp[j]; j++) {
358 + envp[j] = envp[j+1];
362 + if (envp[i] && (strlen(envp[i]) > MAX_ENV_LENGTH)) {
364 + for (j = i; envp[j]; j++) {
365 + envp[j] = envp[j+1];
372 + eq = strchr(envp[i], '=');
375 + len = eq - envp[i];
376 + e = malloc(len + 1);
378 + bad = InternalError;
381 + strncpy(e, envp[i], len);
384 + (strcmp(e + len - 4, "PATH") == 0 ||
385 + strcmp(e, "TERMCAP") == 0)) {
386 + if (strlen(envp[i]) > MAX_ENV_PATH_LENGTH) {
402 + execve(XSERVER_PATH, argv, envp);
403 + fprintf(stderr, "execve failed for %s (errno %d)\n", XSERVER_PATH,
407 + fprintf(stderr, "Command line argument number %d is unsafe\n", i);
408 + fprintf(stderr, ARGMSG);
411 + fprintf(stderr, "Command line argument number %d is too long\n", i);
412 + fprintf(stderr, ARGMSG);
414 + case UnprintableArg:
415 + fprintf(stderr, "Command line argument number %d contains unprintable"
416 + " characters\n", i);
417 + fprintf(stderr, ARGMSG);
420 + fprintf(stderr, "Environment variable `%s' is too long\n", e);
421 + fprintf(stderr, ENVMSG);
423 + case InternalError:
424 + fprintf(stderr, "Internal Error\n");
428 + fprintf(stderr, "Authentication System Failure, "
429 + "missing or mangled PAM configuration file or module?\n");
431 + case PamAuthFailed:
432 + fprintf(stderr, "PAM authentication failed\n");
436 + fprintf(stderr, "Unknown error\n");
437 + fprintf(stderr, ARGMSG);
438 + fprintf(stderr, ENVMSG);
444 diff -urN XFree86-4.1.0.orig/xc/programs/xinit/xinit.c XFree86-4.1.0/xc/programs/xinit/xinit.c
445 --- XFree86-4.1.0.orig/xc/programs/xinit/xinit.c Mon Apr 16 08:51:46 2001
446 +++ XFree86-4.1.0/xc/programs/xinit/xinit.c Sun Jun 17 20:17:24 2001
451 +char *default_wrapper = BINDIR "/Xwrapper";
452 char *default_server = "X";
453 char *default_display = ":0"; /* choose most efficient */
458 (**argv != '/' && **argv != '.')) {
459 - *sptr++ = default_server;
460 + if (access(default_wrapper, X_OK) == 0)
461 + *sptr++ = default_wrapper;
463 + *sptr++ = default_server;
465 (**argv != '/' && **argv != '\\' && **argv != '.' &&
466 !(isalpha(**argv) && (*argv)[1]==':'))) {