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