1 diff -urp -x '*~' -x '*.orig' hw/xfree86/utils/xorgconfig/xorgconfig.c hw/xfree86/utils/xorgconfig/xorgconfig.c |
|
2 --- hw/xfree86/utils/xorgconfig/xorgconfig.c 2008-09-23 11:24:59.000000000 -0700 |
|
3 +++ hw/xfree86/utils/xorgconfig/xorgconfig.c 2008-09-23 16:32:21.769251000 -0700 |
|
4 @@ -1,3 +1,30 @@ |
|
5 +/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. |
|
6 + * |
|
7 + * Permission is hereby granted, free of charge, to any person obtaining a |
|
8 + * copy of this software and associated documentation files (the |
|
9 + * "Software"), to deal in the Software without restriction, including |
|
10 + * without limitation the rights to use, copy, modify, merge, publish, |
|
11 + * distribute, and/or sell copies of the Software, and to permit persons |
|
12 + * to whom the Software is furnished to do so, provided that the above |
|
13 + * copyright notice(s) and this permission notice appear in all copies of |
|
14 + * the Software and that both the above copyright notice(s) and this |
|
15 + * permission notice appear in supporting documentation. |
|
16 + * |
|
17 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
18 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
19 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT |
|
20 + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
21 + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL |
|
22 + * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING |
|
23 + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
|
24 + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
|
25 + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
26 + * |
|
27 + * Except as contained in this notice, the name of a copyright holder |
|
28 + * shall not be used in advertising or otherwise to promote the sale, use |
|
29 + * or other dealings in this Software without prior written authorization |
|
30 + * of the copyright holder. |
|
31 + */ |
|
32 /* |
|
33 * This is a configuration program that will create a base XF86Config |
|
34 * file based on menu choices. Its main feature is that clueless users |
|
35 @@ -112,6 +139,15 @@ |
|
36 |
|
37 #include "cards.h" |
|
38 |
|
39 +#ifdef SUNSOFT /* setuid support for running under RBAC */ |
|
40 +#include <fcntl.h> |
|
41 +#include <netdb.h> |
|
42 +#include <pwd.h> |
|
43 +#include <time.h> |
|
44 +static int euid_changed = 0; |
|
45 +static uid_t saved_id = -1; |
|
46 +static void configdir_check(void); |
|
47 +#endif |
|
48 |
|
49 /* |
|
50 * Define the following to 310 to remove references to XFree86 features that |
|
51 @@ -249,7 +285,11 @@ static char *intro_text = |
|
52 "This program will create a basic " CONFIGNAME " file, based on menu selections\n" |
|
53 "you make. It will ask for a pathname when it is ready to write the file.\n" |
|
54 "\n" |
|
55 +#ifdef SUNSOFT |
|
56 +"The " CONFIGNAME " file usually resides in /etc/X11. If\n" |
|
57 +#else |
|
58 "The " CONFIGNAME " file usually resides in /etc/X11 or " TREEROOTCFG ". If\n" |
|
59 +#endif |
|
60 "no " CONFIGNAME " file is present there, " __XSERVERNAME__" will probe the system to\n" |
|
61 "autoconfigure itself. You can run " __XSERVERNAME__ " -configure to generate a " CONFIGNAME "\n" |
|
62 "file based on the results of autoconfiguration, or let this program\n" |
|
63 @@ -1702,6 +1742,7 @@ skipclockprobing: |
|
64 config_virtual = 0; |
|
65 for (;;) { |
|
66 char modes[128]; |
|
67 + int modes_space_left; |
|
68 |
|
69 emptylines(); |
|
70 |
|
71 @@ -1735,24 +1776,29 @@ skipclockprobing: |
|
72 printf("\n"); |
|
73 |
|
74 modes[0] = '\0'; |
|
75 + modes_space_left = sizeof(modes) - 1; |
|
76 for (i = 0; i < strlen(s); i++) { |
|
77 - if ( NU_MODESTRINGS > 9 ) { |
|
78 - if ((s[i] < '1' || s[i] > '9') && |
|
79 - (s[i] < 'a' || s[i] > 'a' + NU_MODESTRINGS - 10)) { |
|
80 - printf("Invalid mode skipped.\n"); |
|
81 + int choice = -1; |
|
82 + |
|
83 + if ((s[i] >= '1') && (s[i] <= '9')) { |
|
84 + choice = s[i] - '1'; |
|
85 + } else if ((s[i] >= 'a') && |
|
86 + (s[i] <= ('a' + NU_MODESTRINGS - 10))) { |
|
87 + choice = s[i] - 'a' + 9; |
|
88 + } |
|
89 + |
|
90 + if ( (choice < 0) || (choice > NU_MODESTRINGS) ) { |
|
91 + printf("Invalid mode %c skipped.\n", s[i]); |
|
92 continue; |
|
93 - } |
|
94 - } |
|
95 - else { |
|
96 - if (s[i] < '1' || s[i] > '0' + NU_MODESTRINGS) { |
|
97 - printf("Invalid mode skipped.\n"); |
|
98 - continue; |
|
99 - } |
|
100 } |
|
101 - if (i > 0) |
|
102 + if ((i > 0) && (modes_space_left > 1)) { |
|
103 strcat(modes, " "); |
|
104 - strcat(modes, modestring[s[i] <= '9' ? s[i] - '1' : |
|
105 - s[i] - 'a' + 9]); |
|
106 + modes_space_left--; |
|
107 + } |
|
108 + if (modes_space_left > strlen(modestring[choice])) { |
|
109 + modes_space_left -= strlen(modestring[choice]); |
|
110 + strcat(modes, modestring[choice]); |
|
111 + } |
|
112 } |
|
113 switch (c) { |
|
114 case 0 : |
|
115 @@ -1883,10 +1929,21 @@ static char *XF86Config_firstchunk_text |
|
116 "# Load \"type1\"\n" |
|
117 #endif |
|
118 " Load \"freetype\"\n" |
|
119 +#ifndef SUNSOFT |
|
120 "# Load \"xtt\"\n" |
|
121 +#endif |
|
122 "\n" |
|
123 +#ifdef SUNSOFT |
|
124 +"# This loads the SolarisIA module\n" |
|
125 +" Load \"IA\"\n" |
|
126 +"# This loads the GLX module\n" |
|
127 +" Load \"glx\"\n" |
|
128 +"# This loads the Solaris Trusted Extensions module if it is installed\n" |
|
129 +" Load \"xtsol\"\n" |
|
130 +#else |
|
131 "# This loads the GLX module\n" |
|
132 "# Load \"glx\"\n" |
|
133 +#endif |
|
134 "# This loads the DRI module\n" |
|
135 "# Load \"dri\"\n" |
|
136 "\n" |
|
137 @@ -2463,20 +2520,71 @@ write_fontpath_section(FILE *f) |
|
138 static int |
|
139 write_XF86Config(char *filename) |
|
140 { |
|
141 - FILE *f; |
|
142 + FILE *f = NULL; |
|
143 + int fd; |
|
144 + |
|
145 |
|
146 /* |
|
147 * Write the file. |
|
148 */ |
|
149 |
|
150 - f = fopen(filename, "w"); |
|
151 - if (f == NULL) { |
|
152 +#ifdef SUNSOFT |
|
153 + int need_uid_reset = 0; |
|
154 + if (euid_changed && (strcmp(filename, "/etc/X11/"XCONFIGFILE) == 0)) { |
|
155 + if (seteuid(saved_id) == 0) { |
|
156 + need_uid_reset = 1; |
|
157 + } |
|
158 + } |
|
159 + configdir_check(); |
|
160 +#endif |
|
161 + |
|
162 +#if defined(O_NOFOLLOW) && defined(O_NOLINKS) |
|
163 +# define EXTRA_OPEN_FLAGS O_NOFOLLOW | O_NOLINKS |
|
164 +#endif |
|
165 + fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC | EXTRA_OPEN_FLAGS, 0644); |
|
166 + |
|
167 +#ifdef SUNSOFT |
|
168 + if (need_uid_reset) { |
|
169 + if (seteuid(getuid()) != 0) { |
|
170 + perror("xorgconfig: could not reset euid"); |
|
171 + exit(-1); |
|
172 + } |
|
173 + } |
|
174 +#endif |
|
175 + if (fd >= 0) { |
|
176 + f = fdopen(fd, "w"); |
|
177 + } |
|
178 + |
|
179 + if ((fd < 0) || (f == NULL)) { |
|
180 printf("Failed to open filename for writing.\n"); |
|
181 if (getuid() != 0) |
|
182 printf("Maybe you need to be root to write to the specified directory?\n"); |
|
183 return(1); |
|
184 } |
|
185 |
|
186 +#ifdef SUNSOFT |
|
187 + { |
|
188 + char hostname[MAXHOSTNAMELEN] = ""; |
|
189 + struct passwd *pwd = getpwuid(getuid()); |
|
190 + char *username, *timestamp; |
|
191 + time_t now; |
|
192 + |
|
193 + if (pwd == NULL) { |
|
194 + username = Malloc(32); |
|
195 + snprintf(username, 32, "uid %l", (long) getuid()); |
|
196 + } else { |
|
197 + username = pwd->pw_name; |
|
198 + } |
|
199 + |
|
200 + gethostname(hostname, sizeof(hostname)); |
|
201 + |
|
202 + time(&now); |
|
203 + timestamp = ctime(&now); |
|
204 + |
|
205 + fprintf(f, "# Generated by %s on %s at %s\n", |
|
206 + username, hostname, timestamp); |
|
207 + } |
|
208 +#endif |
|
209 fprintf(f, "%s", XF86Config_firstchunk_text); |
|
210 write_fontpath_section(f); |
|
211 fprintf(f, "%s", XF86Config_fontpathchunk_text); |
|
212 @@ -2702,7 +2810,11 @@ ask_XF86Config_location(void) { |
|
213 "I am going to write the " CONFIGNAME " file now. Make sure you don't accidently\n" |
|
214 "overwrite a previously configured one.\n\n"); |
|
215 |
|
216 +#ifdef SUNSOFT |
|
217 + if ((geteuid() == 0) || euid_changed) { |
|
218 +#else |
|
219 if (getuid() == 0) { |
|
220 +#endif |
|
221 #ifdef PREFER_XF86CONFIG_IN_ETC |
|
222 filename = Strdup("/etc/X11/" XCONFIGFILE); |
|
223 filename = append_version(filename); |
|
224 @@ -2713,6 +2825,7 @@ ask_XF86Config_location(void) { |
|
225 return filename; |
|
226 #endif |
|
227 |
|
228 +#ifndef SUNSOFT |
|
229 if (filename) |
|
230 free(filename); |
|
231 filename = Strdup(TREEROOTCFG "/" XCONFIGFILE); |
|
232 @@ -2723,6 +2836,7 @@ ask_XF86Config_location(void) { |
|
233 printf("\n"); |
|
234 if (answerisyes(s)) |
|
235 return filename; |
|
236 +#endif |
|
237 |
|
238 #ifndef PREFER_XF86CONFIG_IN_ETC |
|
239 if (filename) |
|
240 @@ -2824,12 +2938,18 @@ static void |
|
241 configdir_check(void) |
|
242 { |
|
243 /* /etc/X11 may not exist on some systems */ |
|
244 +#ifdef SUNSOFT |
|
245 + if (geteuid() == 0) { |
|
246 +#else |
|
247 if (getuid() == 0) { |
|
248 +#endif |
|
249 struct stat buf; |
|
250 if (stat("/etc/X11", &buf) == -1 && errno == ENOENT) |
|
251 mkdir("/etc/X11", 0777); |
|
252 +#ifndef SUNSOFT |
|
253 if (stat(TREEROOTCFG, &buf) == -1 && errno == ENOENT) |
|
254 mkdir(TREEROOTCFG, 0777); |
|
255 +#endif |
|
256 } |
|
257 } |
|
258 |
|
259 @@ -2840,6 +2960,19 @@ configdir_check(void) |
|
260 |
|
261 int |
|
262 main(int argc, char *argv[]) { |
|
263 + |
|
264 +#ifdef SUNSOFT |
|
265 + /* Try to run more securely when being run seteuid via RBAC */ |
|
266 + if (issetugid() || (geteuid() != getuid())) { |
|
267 + saved_id = geteuid(); |
|
268 + if (seteuid(getuid()) == 0) { |
|
269 + euid_changed = 1; |
|
270 + } else { |
|
271 + perror("xorgconfig: could not reset euid"); |
|
272 + exit(-1); |
|
273 + } |
|
274 + } |
|
275 +#endif |
|
276 |
|
277 createtmpdir(); |
|
278 |
|
279 @@ -2854,9 +2987,11 @@ main(int argc, char *argv[]) { |
|
280 |
|
281 emptylines(); |
|
282 |
|
283 +#ifndef SUNSOFT /* Moved into write_XF86Config */ |
|
284 configdir_check(); |
|
285 |
|
286 emptylines(); |
|
287 +#endif |
|
288 |
|
289 mouse_configuration(); |
|
290 |
|