]> git.pld-linux.org Git - packages/XFree86.git/blame - XFree86-Xwrapper.patch
- cleaned up mess done by cieciwa
[packages/XFree86.git] / XFree86-Xwrapper.patch
CommitLineData
b19d4d8b
JR
1diff -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
e2d64aaf
JR
4@@ -31,8 +31,14 @@
5 #ifndef MakeDllModules
6 #define MakeDllModules NO
7 #endif
8+#ifndef XserverNeedsSetUID
9+#define XserverNeedsSetUID NO
10+#endif
11+#ifndef UseXserverWrapper
12+#define UseXserverWrapper XserverNeedsSetUID
13+#endif
14 #ifndef InstallServerSetUID
15-#define InstallServerSetUID NO
16+#define InstallServerSetUID (XserverNeedsSetUID && !UseXserverWrapper)
17 #endif
18
19 /*
b19d4d8b
JR
20diff -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
23@@ -348,13 +348,15 @@
e2d64aaf
JR
24 */
25
26 /*
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
36+ * wrapper.
37 *
38-#define InstallXserverSetUID NO
39+ * If you're only starting the Xservers with xdm set this to NO
40+ *
41+#define XserverNeedsSetUID NO
42 */
43
44 /*
b19d4d8b
JR
45diff -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
48@@ -585,12 +585,15 @@
e2d64aaf
JR
49 #endif
50
51 /*
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
58+ * wrapper.
59 */
60 #if !defined(i386MachArchitecture) && !defined(OS2Architecture)
61-# ifndef InstallXserverSetUID
62-# define InstallXserverSetUID YES
63+# ifndef XserverNeedsSetUID
64+# define XserverNeedsSetUID YES
65 # endif
66 #endif
67
b19d4d8b
JR
68diff -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
e2d64aaf
JR
71@@ -4,11 +4,6 @@
72 */
b19d4d8b 73 XCOMM $XFree86: xc/programs/Xserver/Imakefile,v 3.205 2000/12/11 20:29:31 dawes Exp $
e2d64aaf
JR
74
75-#ifndef InstallXserverSetUID
76-#define InstallXserverSetUID NO
77-#endif
78-#define InstallServerSetUID InstallXserverSetUID
79-
80 #include <Server.tmpl>
81
82 #ifdef XFree86Version
b19d4d8b
JR
83@@ -264,7 +259,7 @@
84 EXTRASYSLIBS = ServerExtraSysLibs
e2d64aaf 85 #endif
b19d4d8b
JR
86 #if HasPam && HasPamMisc
87- PAMLIBS = PamLibraries PamMiscLibraries
88+ PAMLIBS = -lpam -lpam_misc -ldl PamLibraries PamMiscLibraries
89 #endif
90 #if !(SystemV4 || defined(SGIArchitecture) || UseRgbTxt)
91 DBMLIBS = DBMLibrary
92@@ -1017,6 +1012,11 @@
93 $(XNESTLIBS) $(LOADABLEEXTS) $(LIBCWRAPPER),$(XNESTSYSLIBS))
94 #endif /* XnestServer */
e2d64aaf
JR
95
96+
97+#if UseXserverWrapper
98+SetUIDProgramTarget(Xwrapper,os/wrapper.o,NullParameter,$(PAMLIBS),NullParameter)
99+InstallProgramWithFlags(Xwrapper,$(BINDIR),$(INSTUIDFLAGS))
100+#endif
101
b19d4d8b
JR
102 #if XnonServer
103 XCOMM
104diff -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
107@@ -66,7 +66,10 @@
e2d64aaf
JR
108 /* check if we're run with euid==0 */
109 if (geteuid() != 0)
110 {
111- FatalError("xf86OpenConsole: Server must be suid root\n");
112+ FatalError("xf86OpenConsole: Server must be running with root "
113+ "permissions\n"
114+ "You should be using Xwrapper to start the server or xdm.\n"
115+ "We strongly advise against making the server SUID root!\n");
116 }
117
118 /*
b19d4d8b
JR
119diff -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
122@@ -113,6 +113,7 @@
123 #endif
e2d64aaf
JR
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
129
b19d4d8b 130@@ -156,6 +157,14 @@
e2d64aaf
JR
131 cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c
132 #else
133 SpecialCObjectRule(oscolor,$(ICONFIGFILES),$(DBM_DEFINES))
134+#endif
135+
136+#if UseXserverWrapper
137+AllTarget(wrapper.o)
138+
139+ WRAPPER_DEFINES = -DXSERVER_PATH=\"/etc/X11/X\"
140+
141+SpecialCObjectRule(wrapper,NullParameter,$(WRAPPER_DEFINES))
142 #endif
143
144 #if HasKrb5
b19d4d8b
JR
145diff -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
e2d64aaf
JR
148@@ -0,0 +1,304 @@
149+/*
150+ * X server wrapper.
151+ *
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.
156+ */
157+
158+/*
159+ * Copyright (c) 1998 by The XFree86 Project, Inc. All Rights Reserved.
160+ *
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:
168+ *
169+ * The above copyright notice and this permission notice shall be included
170+ * in all copies or substantial portions of the Software.
171+ *
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.
179+ *
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.
184+ */
185+
186+/* $XFree86: xc/programs/Xserver/os/wrapper.c,v 1.1.2.5 1998/02/27 15:28:59 dawes Exp $ */
187+
188+/* This is normally set in the Imakefile */
189+#ifndef XSERVER_PATH
190+#define XSERVER_PATH "/etc/X11/X"
191+#endif
192+
193+#include <stdio.h>
194+#include <stdlib.h>
195+#include <string.h>
196+#include <errno.h>
197+#include <unistd.h>
198+#include <sys/types.h>
199+#ifdef USE_PAM
200+#include <security/pam_appl.h>
201+#include <security/pam_misc.h>
202+#include <pwd.h>
203+#endif /* USE_PAM */
204+
205+/* Neither of these should be required for XFree86 3.3.2 */
206+#ifndef REJECT_CONFIG
207+#define REJECT_CONFIG 0
208+#endif
209+#ifndef REJECT_XKBDIR
210+#define REJECT_XKBDIR 0
211+#endif
212+
213+/* Consider LD* variables insecure ? */
214+#ifndef REMOVE_ENV_LD
215+#define REMOVE_ENV_LD 1
216+#endif
217+
218+/* Remove long environment variables? */
219+#ifndef REMOVE_LONG_ENV
220+#define REMOVE_LONG_ENV 1
221+#endif
222+
223+/* Check args and env only if running setuid (euid == 0 && euid != uid) ? */
224+#ifndef CHECK_EUID
225+#define CHECK_EUID 1
226+#endif
227+
228+/*
229+ * Maybe the locale can be faked to make isprint(3) report that everything
230+ * is printable? Avoid it by default.
231+ */
232+#ifndef USE_ISPRINT
233+#define USE_ISPRINT 0
234+#endif
235+
236+#define MAX_ARG_LENGTH 128
237+#define MAX_ENV_LENGTH 256
238+#define MAX_ENV_PATH_LENGTH 2048
239+
240+#if USE_ISPRINT
241+#include <ctype.h>
242+#define checkPrintable(c) isprint(c)
243+#else
244+#define checkPrintable(c) (((c) & 0x7f) >= 0x20 && ((c) & 0x7f) != 0x7f)
245+#endif
246+
247+enum BadCode {
248+ NotBad = 0,
249+ UnsafeArg,
250+ ArgTooLong,
251+ UnprintableArg,
252+ EnvTooLong,
253+ InternalError,
254+#ifdef USE_PAM
255+ PamFailed,
256+ PamAuthFailed,
257+#endif /* USE_PAM */
258+};
259+
260+#define ARGMSG \
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"
265+
266+#define ENVMSG \
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"
271+
272+#ifdef USE_PAM
273+static struct pam_conv conv = {
274+ misc_conv,
275+ NULL
276+};
277+#endif /* USE_PAM */
278+
279+
280+int
281+main(int argc, char **argv, char **envp)
282+{
283+ enum BadCode bad = NotBad;
284+ int i, j;
285+ char *a, *e;
286+#ifdef USE_PAM
287+ pam_handle_t *pamh = NULL;
288+ struct passwd *pw;
289+ int retval;
290+
291+ pw = getpwuid(getuid());
292+ if (pw == NULL) {
293+ bad = InternalError;
294+ }
295+
296+ if (!bad) {
297+ retval = pam_start("xserver", pw->pw_name, &conv, &pamh);
298+ if (retval != PAM_SUCCESS)
299+ bad = PamFailed;
300+ }
301+
302+ if (!bad) {
303+ retval = pam_authenticate(pamh, 0);
304+ if (retval != PAM_SUCCESS) {
305+ pam_end(pamh, retval);
306+ bad = PamAuthFailed;
307+ }
308+ }
309+
310+ if (!bad) {
311+ retval = pam_acct_mgmt(pamh, 0);
312+ if (retval != PAM_SUCCESS) {
313+ pam_end(pamh, retval);
314+ bad = PamAuthFailed;
315+ }
316+ }
317+
318+ /* this is not a session, so do not do session management */
319+
320+ if (!bad) pam_end(pamh, PAM_SUCCESS);
321+#endif /* USE_PAM */
322+
323+#if CHECK_EUID
324+ if (!bad && geteuid() == 0 && getuid() != geteuid()) {
325+#else
326+ if (!bad) {
327+#endif
328+ /* Check each argv[] */
329+ for (i = 1; i < argc; i++) {
330+
331+ /* Check for known bad arguments */
332+#if REJECT_CONFIG
333+ if (strcmp(argv[i], "-config") == 0) {
334+ bad = UnsafeArg;
335+ break;
336+ }
337+#endif
338+#if REJECT_XKBDIR
339+ if (strcmp(argv[i], "-xkbdir") == 0) {
340+ bad = UnsafeArg;
341+ break;
342+ }
343+#endif
344+ if (strlen(argv[i]) > MAX_ARG_LENGTH) {
345+ bad = ArgTooLong;
346+ break;
347+ }
348+ a = argv[i];
349+ while (*a) {
350+ if (checkPrintable(*a) == 0) {
351+ bad = UnprintableArg;
352+ break;
353+ }
354+ a++;
355+ }
356+ if (bad)
357+ break;
358+ }
359+ /* Check each envp[] */
360+ if (!bad)
361+ for (i = 0; envp[i]; i++) {
362+
363+ /* Check for bad environment variables and values */
364+#if REMOVE_ENV_LD
365+ while (envp[i] && (strncmp(envp[i], "LD", 2) == 0)) {
366+ for (j = i; envp[j]; j++) {
367+ envp[j] = envp[j+1];
368+ }
369+ }
370+#endif
371+ if (envp[i] && (strlen(envp[i]) > MAX_ENV_LENGTH)) {
372+#if REMOVE_LONG_ENV
373+ for (j = i; envp[j]; j++) {
374+ envp[j] = envp[j+1];
375+ }
376+ i--;
377+#else
378+ char *eq;
379+ int len;
380+
381+ eq = strchr(envp[i], '=');
382+ if (!eq)
383+ continue;
384+ len = eq - envp[i];
385+ e = malloc(len + 1);
386+ if (!e) {
387+ bad = InternalError;
388+ break;
389+ }
390+ strncpy(e, envp[i], len);
391+ e[len] = 0;
392+ if (len >= 4 &&
393+ (strcmp(e + len - 4, "PATH") == 0 ||
394+ strcmp(e, "TERMCAP") == 0)) {
395+ if (strlen(envp[i]) > MAX_ENV_PATH_LENGTH) {
396+ bad = EnvTooLong;
397+ break;
398+ } else {
399+ free(e);
400+ }
401+ } else {
402+ bad = EnvTooLong;
403+ break;
404+ }
405+#endif
406+ }
407+ }
408+ }
409+ switch (bad) {
410+ case NotBad:
411+ execve(XSERVER_PATH, argv, envp);
412+ fprintf(stderr, "execve failed for %s (errno %d)\n", XSERVER_PATH,
413+ errno);
414+ break;
415+ case UnsafeArg:
416+ fprintf(stderr, "Command line argument number %d is unsafe\n", i);
417+ fprintf(stderr, ARGMSG);
418+ break;
419+ case ArgTooLong:
420+ fprintf(stderr, "Command line argument number %d is too long\n", i);
421+ fprintf(stderr, ARGMSG);
422+ break;
423+ case UnprintableArg:
424+ fprintf(stderr, "Command line argument number %d contains unprintable"
425+ " characters\n", i);
426+ fprintf(stderr, ARGMSG);
427+ break;
428+ case EnvTooLong:
429+ fprintf(stderr, "Environment variable `%s' is too long\n", e);
430+ fprintf(stderr, ENVMSG);
431+ break;
432+ case InternalError:
433+ fprintf(stderr, "Internal Error\n");
434+ break;
435+#ifdef USE_PAM
436+ case PamFailed:
437+ fprintf(stderr, "Authentication System Failure, "
438+ "missing or mangled PAM configuration file or module?\n");
439+ break;
440+ case PamAuthFailed:
441+ fprintf(stderr, "PAM authentication failed\n");
442+ break;
443+#endif
444+ default:
445+ fprintf(stderr, "Unknown error\n");
446+ fprintf(stderr, ARGMSG);
447+ fprintf(stderr, ENVMSG);
448+ break;
449+ }
450+ exit(1);
451+}
452+
b19d4d8b
JR
453diff -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
456@@ -147,6 +147,7 @@
e2d64aaf
JR
457 #define OK_EXIT 0
458 #define ERR_EXIT 1
459
460+char *default_wrapper = BINDIR "/Xwrapper";
461 char *default_server = "X";
462 char *default_display = ":0"; /* choose most efficient */
463 #ifndef __EMX__
b19d4d8b 464@@ -316,7 +317,10 @@
e2d64aaf
JR
465 if (argc == 0 ||
466 #ifndef __EMX__
467 (**argv != '/' && **argv != '.')) {
468- *sptr++ = default_server;
469+ if (access(default_wrapper, X_OK) == 0)
470+ *sptr++ = default_wrapper;
471+ else
472+ *sptr++ = default_server;
473 #else
474 (**argv != '/' && **argv != '\\' && **argv != '.' &&
475 !(isalpha(**argv) && (*argv)[1]==':'))) {
This page took 0.076344 seconds and 4 git commands to generate.