1 diff -Nur XFree86-4.0.2.org/xc/config/cf/Server.tmpl XFree86-4.0.2/xc/config/cf/Server.tmpl
2 --- XFree86-4.0.2.org/xc/config/cf/Server.tmpl Fri Feb 18 17:23:07 2000
3 +++ XFree86-4.0.2/xc/config/cf/Server.tmpl Thu Dec 21 08:47:33 2000
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 -Nur XFree86-4.0.2.org/xc/config/cf/xf86site.def XFree86-4.0.2/xc/config/cf/xf86site.def
21 --- XFree86-4.0.2.org/xc/config/cf/xf86site.def Thu Dec 21 09:01:05 2000
22 +++ XFree86-4.0.2/xc/config/cf/xf86site.def Thu Dec 21 08:47:33 2000
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 -Nur XFree86-4.0.2.org/xc/config/cf/xfree86.cf XFree86-4.0.2/xc/config/cf/xfree86.cf
46 --- XFree86-4.0.2.org/xc/config/cf/xfree86.cf Thu Dec 21 09:01:06 2000
47 +++ XFree86-4.0.2/xc/config/cf/xfree86.cf Thu Dec 21 08:47:33 2000
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 -Nur XFree86-4.0.2.org/xc/programs/Xserver/Imakefile XFree86-4.0.2/xc/programs/Xserver/Imakefile
69 --- XFree86-4.0.2.org/xc/programs/Xserver/Imakefile Wed Dec 13 00:58:58 2000
70 +++ XFree86-4.0.2/xc/programs/Xserver/Imakefile Thu Dec 21 08:54:16 2000
73 XCOMM $XFree86: xc/programs/Xserver/Imakefile,v 3.205 2000/12/11 20:29:31 dawes Exp $
75 -#ifndef InstallXserverSetUID
76 -#define InstallXserverSetUID NO
78 -#define InstallServerSetUID InstallXserverSetUID
80 #include <Server.tmpl>
84 EXTRASYSLIBS = ServerExtraSysLibs
86 #if HasPam && HasPamMisc
87 - PAMLIBS = PamLibraries PamMiscLibraries
88 + PAMLIBS = -lpam -lpam_misc -ldl PamLibraries PamMiscLibraries
90 #if !(SystemV4 || defined(SGIArchitecture) || UseRgbTxt)
92 @@ -1017,6 +1012,11 @@
93 $(XNESTLIBS) $(LOADABLEEXTS) $(LIBCWRAPPER),$(XNESTSYSLIBS))
94 #endif /* XnestServer */
97 +#if UseXserverWrapper
98 +SetUIDProgramTarget(Xwrapper,os/wrapper.o,NullParameter,$(PAMLIBS),NullParameter)
99 +InstallProgramWithFlags(Xwrapper,$(BINDIR),$(INSTUIDFLAGS))
104 diff -Nur XFree86-4.0.2.org/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c XFree86-4.0.2/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c
105 --- XFree86-4.0.2.org/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c Wed Nov 29 17:43:28 2000
106 +++ XFree86-4.0.2/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c Thu Dec 21 08:47:33 2000
108 /* check if we're run with euid==0 */
111 - FatalError("xf86OpenConsole: Server must be suid root\n");
112 + FatalError("xf86OpenConsole: Server must be running with root "
114 + "You should be using Xwrapper to start the server or xdm.\n"
115 + "We strongly advise against making the server SUID root!\n");
119 diff -Nur XFree86-4.0.2.org/xc/programs/Xserver/os/Imakefile XFree86-4.0.2/xc/programs/Xserver/os/Imakefile
120 --- XFree86-4.0.2.org/xc/programs/Xserver/os/Imakefile Tue Dec 5 01:59:14 2000
121 +++ XFree86-4.0.2/xc/programs/Xserver/os/Imakefile Thu Dec 21 08:47:33 2000
124 DEFINES = -DXSERV_t -DTRANS_SERVER $(CONNECTION_FLAGS) $(MEM_DEFINES) $(XDMAUTHDEFS) $(RPCDEFS) $(SIGNAL_DEFINES) $(OS_DEFINES) $(KRB5_DEFINES) $(RGB_DEFINES)
125 INCLUDES = -I. -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(TOP)/lib/Xau -I../lbx Krb5Includes
126 + EXTRA_DEFINES = -DUSE_PAM
127 DEPEND_DEFINES = $(DBM_DEFINES) $(XDMCP_DEFINES) $(EXT_DEFINES) $(TRANS_INCLUDES) $(CONNECTION_FLAGS)
128 LINTLIBS = ../dix/llib-ldix.ln
131 cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c
133 SpecialCObjectRule(oscolor,$(ICONFIGFILES),$(DBM_DEFINES))
136 +#if UseXserverWrapper
137 +AllTarget(wrapper.o)
139 + WRAPPER_DEFINES = -DXSERVER_PATH=\"/etc/X11/X\"
141 +SpecialCObjectRule(wrapper,NullParameter,$(WRAPPER_DEFINES))
145 diff -Nur XFree86-4.0.2.org/xc/programs/Xserver/os/wrapper.c XFree86-4.0.2/xc/programs/Xserver/os/wrapper.c
146 --- XFree86-4.0.2.org/xc/programs/Xserver/os/wrapper.c Thu Jan 1 01:00:00 1970
147 +++ XFree86-4.0.2/xc/programs/Xserver/os/wrapper.c Thu Dec 21 08:47:33 2000
150 + * X server wrapper.
152 + * This wrapper makes some sanity checks on the command line arguments
153 + * and environment variables when run with euid == 0 && euid != uid.
154 + * If the checks fail, the wrapper exits with a message.
155 + * If they succeed, it exec's the Xserver.
159 + * Copyright (c) 1998 by The XFree86 Project, Inc. All Rights Reserved.
161 + * Permission is hereby granted, free of charge, to any person obtaining
162 + * a copy of this software and associated documentation files (the
163 + * "Software"), to deal in the Software without restriction, including
164 + * without limitation the rights to use, copy, modify, merge, publish,
165 + * distribute, sublicense, and/or sell copies of the Software, and to
166 + * permit persons to whom the Software is furnished to do so, subject
167 + * to the following conditions:
169 + * The above copyright notice and this permission notice shall be included
170 + * in all copies or substantial portions of the Software.
172 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
173 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
174 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
175 + * IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES
176 + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
177 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
178 + * OR OTHER DEALINGS IN THE SOFTWARE.
180 + * Except as contained in this notice, the name of the XFree86 Project
181 + * shall not be used in advertising or otherwise to promote the sale,
182 + * use or other dealings in this Software without prior written
183 + * authorization from the XFree86 Project.
186 +/* $XFree86: xc/programs/Xserver/os/wrapper.c,v 1.1.2.5 1998/02/27 15:28:59 dawes Exp $ */
188 +/* This is normally set in the Imakefile */
189 +#ifndef XSERVER_PATH
190 +#define XSERVER_PATH "/etc/X11/X"
198 +#include <sys/types.h>
200 +#include <security/pam_appl.h>
201 +#include <security/pam_misc.h>
203 +#endif /* USE_PAM */
205 +/* Neither of these should be required for XFree86 3.3.2 */
206 +#ifndef REJECT_CONFIG
207 +#define REJECT_CONFIG 0
209 +#ifndef REJECT_XKBDIR
210 +#define REJECT_XKBDIR 0
213 +/* Consider LD* variables insecure ? */
214 +#ifndef REMOVE_ENV_LD
215 +#define REMOVE_ENV_LD 1
218 +/* Remove long environment variables? */
219 +#ifndef REMOVE_LONG_ENV
220 +#define REMOVE_LONG_ENV 1
223 +/* Check args and env only if running setuid (euid == 0 && euid != uid) ? */
225 +#define CHECK_EUID 1
229 + * Maybe the locale can be faked to make isprint(3) report that everything
230 + * is printable? Avoid it by default.
233 +#define USE_ISPRINT 0
236 +#define MAX_ARG_LENGTH 128
237 +#define MAX_ENV_LENGTH 256
238 +#define MAX_ENV_PATH_LENGTH 2048
242 +#define checkPrintable(c) isprint(c)
244 +#define checkPrintable(c) (((c) & 0x7f) >= 0x20 && ((c) & 0x7f) != 0x7f)
257 +#endif /* USE_PAM */
261 + "\nIf the arguments used are valid, and have been rejected incorrectly\n" \
262 + "please send details of the arguments and why they are valid to\n" \
263 + "XFree86@XFree86.org. In the meantime, you can start the Xserver as\n" \
264 + "the \"super user\" (root).\n"
267 + "\nIf the environment is valid, and have been rejected incorrectly\n" \
268 + "please send details of the environment and why it is valid to\n" \
269 + "XFree86@XFree86.org. In the meantime, you can start the Xserver as\n" \
270 + "the \"super user\" (root).\n"
273 +static struct pam_conv conv = {
277 +#endif /* USE_PAM */
281 +main(int argc, char **argv, char **envp)
283 + enum BadCode bad = NotBad;
287 + pam_handle_t *pamh = NULL;
291 + pw = getpwuid(getuid());
293 + bad = InternalError;
297 + retval = pam_start("xserver", pw->pw_name, &conv, &pamh);
298 + if (retval != PAM_SUCCESS)
303 + retval = pam_authenticate(pamh, 0);
304 + if (retval != PAM_SUCCESS) {
305 + pam_end(pamh, retval);
306 + bad = PamAuthFailed;
311 + retval = pam_acct_mgmt(pamh, 0);
312 + if (retval != PAM_SUCCESS) {
313 + pam_end(pamh, retval);
314 + bad = PamAuthFailed;
318 + /* this is not a session, so do not do session management */
320 + if (!bad) pam_end(pamh, PAM_SUCCESS);
321 +#endif /* USE_PAM */
324 + if (!bad && geteuid() == 0 && getuid() != geteuid()) {
328 + /* Check each argv[] */
329 + for (i = 1; i < argc; i++) {
331 + /* Check for known bad arguments */
333 + if (strcmp(argv[i], "-config") == 0) {
339 + if (strcmp(argv[i], "-xkbdir") == 0) {
344 + if (strlen(argv[i]) > MAX_ARG_LENGTH) {
350 + if (checkPrintable(*a) == 0) {
351 + bad = UnprintableArg;
359 + /* Check each envp[] */
361 + for (i = 0; envp[i]; i++) {
363 + /* Check for bad environment variables and values */
365 + while (envp[i] && (strncmp(envp[i], "LD", 2) == 0)) {
366 + for (j = i; envp[j]; j++) {
367 + envp[j] = envp[j+1];
371 + if (envp[i] && (strlen(envp[i]) > MAX_ENV_LENGTH)) {
373 + for (j = i; envp[j]; j++) {
374 + envp[j] = envp[j+1];
381 + eq = strchr(envp[i], '=');
384 + len = eq - envp[i];
385 + e = malloc(len + 1);
387 + bad = InternalError;
390 + strncpy(e, envp[i], len);
393 + (strcmp(e + len - 4, "PATH") == 0 ||
394 + strcmp(e, "TERMCAP") == 0)) {
395 + if (strlen(envp[i]) > MAX_ENV_PATH_LENGTH) {
411 + execve(XSERVER_PATH, argv, envp);
412 + fprintf(stderr, "execve failed for %s (errno %d)\n", XSERVER_PATH,
416 + fprintf(stderr, "Command line argument number %d is unsafe\n", i);
417 + fprintf(stderr, ARGMSG);
420 + fprintf(stderr, "Command line argument number %d is too long\n", i);
421 + fprintf(stderr, ARGMSG);
423 + case UnprintableArg:
424 + fprintf(stderr, "Command line argument number %d contains unprintable"
425 + " characters\n", i);
426 + fprintf(stderr, ARGMSG);
429 + fprintf(stderr, "Environment variable `%s' is too long\n", e);
430 + fprintf(stderr, ENVMSG);
432 + case InternalError:
433 + fprintf(stderr, "Internal Error\n");
437 + fprintf(stderr, "Authentication System Failure, "
438 + "missing or mangled PAM configuration file or module?\n");
440 + case PamAuthFailed:
441 + fprintf(stderr, "PAM authentication failed\n");
445 + fprintf(stderr, "Unknown error\n");
446 + fprintf(stderr, ARGMSG);
447 + fprintf(stderr, ENVMSG);
453 diff -Nur XFree86-4.0.2.org/xc/programs/xinit/xinit.c XFree86-4.0.2/xc/programs/xinit/xinit.c
454 --- XFree86-4.0.2.org/xc/programs/xinit/xinit.c Tue Nov 7 00:06:04 2000
455 +++ XFree86-4.0.2/xc/programs/xinit/xinit.c Thu Dec 21 08:47:33 2000
460 +char *default_wrapper = BINDIR "/Xwrapper";
461 char *default_server = "X";
462 char *default_display = ":0"; /* choose most efficient */
467 (**argv != '/' && **argv != '.')) {
468 - *sptr++ = default_server;
469 + if (access(default_wrapper, X_OK) == 0)
470 + *sptr++ = default_wrapper;
472 + *sptr++ = default_server;
474 (**argv != '/' && **argv != '\\' && **argv != '.' &&
475 !(isalpha(**argv) && (*argv)[1]==':'))) {