1 --- os/wrapper.c 1970-01-01 01:00:00.000000000 +0100
2 +++ os/wrapper.c 2005-12-22 10:50:53.610963000 +0100
7 + * This wrapper makes some sanity checks on the command line arguments
8 + * and environment variables when run with euid == 0 && euid != uid.
9 + * If the checks fail, the wrapper exits with a message.
10 + * If they succeed, it exec's the Xserver.
14 + * Copyright (c) 1998 by The XFree86 Project, Inc. All Rights Reserved.
16 + * Permission is hereby granted, free of charge, to any person obtaining
17 + * a copy of this software and associated documentation files (the
18 + * "Software"), to deal in the Software without restriction, including
19 + * without limitation the rights to use, copy, modify, merge, publish,
20 + * distribute, sublicense, and/or sell copies of the Software, and to
21 + * permit persons to whom the Software is furnished to do so, subject
22 + * to the following conditions:
24 + * The above copyright notice and this permission notice shall be included
25 + * in all copies or substantial portions of the Software.
27 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
30 + * IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES
31 + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
32 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
33 + * OR OTHER DEALINGS IN THE SOFTWARE.
35 + * Except as contained in this notice, the name of the XFree86 Project
36 + * shall not be used in advertising or otherwise to promote the sale,
37 + * use or other dealings in this Software without prior written
38 + * authorization from the XFree86 Project.
41 +/* $XFree86: xc/programs/Xserver/os/wrapper.c,v 1.1.2.5 1998/02/27 15:28:59 dawes Exp $ */
43 +/* This is normally set in the Imakefile */
45 +#define XSERVER_PATH "/etc/X11/X"
53 +#include <sys/types.h>
55 +#include <security/pam_appl.h>
56 +#include <security/pam_misc.h>
60 +/* Neither of these should be required for XFree86 3.3.2 */
61 +#ifndef REJECT_CONFIG
62 +#define REJECT_CONFIG 0
64 +#ifndef REJECT_XKBDIR
65 +#define REJECT_XKBDIR 0
68 +/* Consider LD* variables insecure ? */
69 +#ifndef REMOVE_ENV_LD
70 +#define REMOVE_ENV_LD 1
73 +/* Remove long environment variables? */
74 +#ifndef REMOVE_LONG_ENV
75 +#define REMOVE_LONG_ENV 1
78 +/* Check args and env only if running setuid (euid == 0 && euid != uid) ? */
84 + * Maybe the locale can be faked to make isprint(3) report that everything
85 + * is printable? Avoid it by default.
88 +#define USE_ISPRINT 0
91 +#define MAX_ARG_LENGTH 128
92 +#define MAX_ENV_LENGTH 256
93 +#define MAX_ENV_PATH_LENGTH 2048
97 +#define checkPrintable(c) isprint(c)
99 +#define checkPrintable(c) (((c) & 0x7f) >= 0x20 && ((c) & 0x7f) != 0x7f)
112 +#endif /* USE_PAM */
116 + "\nIf the arguments used are valid, and have been rejected incorrectly\n" \
117 + "please send details of the arguments and why they are valid to\n" \
118 + "XFree86@XFree86.org. In the meantime, you can start the Xserver as\n" \
119 + "the \"super user\" (root).\n"
122 + "\nIf the environment is valid, and have been rejected incorrectly\n" \
123 + "please send details of the environment and why it is valid to\n" \
124 + "XFree86@XFree86.org. In the meantime, you can start the Xserver as\n" \
125 + "the \"super user\" (root).\n"
128 +static struct pam_conv conv = {
132 +#endif /* USE_PAM */
136 +main(int argc, char **argv, char **envp)
138 + enum BadCode bad = NotBad;
142 + pam_handle_t *pamh = NULL;
146 + pw = getpwuid(getuid());
148 + bad = InternalError;
152 + retval = pam_start("xserver", pw->pw_name, &conv, &pamh);
153 + if (retval != PAM_SUCCESS)
158 + retval = pam_authenticate(pamh, 0);
159 + if (retval != PAM_SUCCESS) {
160 + pam_end(pamh, retval);
161 + bad = PamAuthFailed;
166 + retval = pam_acct_mgmt(pamh, 0);
167 + if (retval != PAM_SUCCESS) {
168 + pam_end(pamh, retval);
169 + bad = PamAuthFailed;
173 + /* this is not a session, so do not do session management */
175 + if (!bad) pam_end(pamh, PAM_SUCCESS);
176 +#endif /* USE_PAM */
179 + if (!bad && geteuid() == 0 && getuid() != geteuid()) {
183 + /* Check each argv[] */
184 + for (i = 1; i < argc; i++) {
186 + /* Check for known bad arguments */
188 + if (strcmp(argv[i], "-config") == 0) {
194 + if (strcmp(argv[i], "-xkbdir") == 0) {
199 + if (strlen(argv[i]) > MAX_ARG_LENGTH) {
205 + if (checkPrintable(*a) == 0) {
206 + bad = UnprintableArg;
214 + /* Check each envp[] */
216 + for (i = 0; envp[i]; i++) {
218 + /* Check for bad environment variables and values */
220 + while (envp[i] && (strncmp(envp[i], "LD", 2) == 0)) {
221 + for (j = i; envp[j]; j++) {
222 + envp[j] = envp[j+1];
226 + if (envp[i] && (strlen(envp[i]) > MAX_ENV_LENGTH)) {
228 + for (j = i; envp[j]; j++) {
229 + envp[j] = envp[j+1];
236 + eq = strchr(envp[i], '=');
239 + len = eq - envp[i];
240 + e = malloc(len + 1);
242 + bad = InternalError;
245 + strncpy(e, envp[i], len);
248 + (strcmp(e + len - 4, "PATH") == 0 ||
249 + strcmp(e, "TERMCAP") == 0)) {
250 + if (strlen(envp[i]) > MAX_ENV_PATH_LENGTH) {
266 + execve(XSERVER_PATH, argv, envp);
267 + fprintf(stderr, "execve failed for %s (errno %d)\n", XSERVER_PATH,
271 + fprintf(stderr, "Command line argument number %d is unsafe\n", i);
272 + fprintf(stderr, ARGMSG);
275 + fprintf(stderr, "Command line argument number %d is too long\n", i);
276 + fprintf(stderr, ARGMSG);
278 + case UnprintableArg:
279 + fprintf(stderr, "Command line argument number %d contains unprintable"
280 + " characters\n", i);
281 + fprintf(stderr, ARGMSG);
284 + fprintf(stderr, "Environment variable `%s' is too long\n", e);
285 + fprintf(stderr, ENVMSG);
287 + case InternalError:
288 + fprintf(stderr, "Internal Error\n");
292 + fprintf(stderr, "Authentication System Failure, "
293 + "missing or mangled PAM configuration file or module?\n");
295 + case PamAuthFailed:
296 + fprintf(stderr, "PAM authentication failed\n");
300 + fprintf(stderr, "Unknown error\n");
301 + fprintf(stderr, ARGMSG);
302 + fprintf(stderr, ENVMSG);
308 --- os/Makefile.am 2005-12-06 16:50:35.000000000 +0100
309 +++ os/Makefile.am 2006-02-05 14:36:53.211755250 +0100
314 +bin_PROGRAMS = Xwrapper
315 +Xwrapper_SOURCES = wrapper.c
316 +Xwrapper_CFLAGS = -DUSE_PAM -DXSERVER_PATH=\"/usr/bin/Xorg\" $(AM_CFLAGS)
317 +Xwrapper_LDADD = -lpam_misc
320 libos_la_SOURCES += $(SECURERPC_SRCS)