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