]>
Commit | Line | Data |
---|---|---|
340ec576 | 1 | --- xc/programs/xfs/difs/fonts.c.xfsredhat Sun Aug 22 15:29:55 1999 |
2 | +++ xc/programs/xfs/difs/fonts.c Tue Mar 14 12:10:39 2000 | |
3 | @@ -108,6 +108,113 @@ | |
505397d5 | 4 | } |
5 | ||
6 | /* | |
7 | + * xf86GetPathElem -- | |
8 | + * Extract a single element from the font path string starting at | |
9 | + * pnt. The font path element will be returned, and pnt will be | |
10 | + * updated to point to the start of the next element, or set to | |
11 | + * NULL if there are no more. | |
12 | + */ | |
13 | +char * | |
14 | +xf86GetPathElem(pnt) | |
15 | + char **pnt; | |
16 | +{ | |
17 | + char *p1; | |
18 | + | |
19 | + p1 = *pnt; | |
20 | + *pnt = index(*pnt, ','); | |
21 | + if (*pnt != NULL) { | |
22 | + **pnt = '\0'; | |
23 | + *pnt += 1; | |
24 | + } | |
25 | + return(p1); | |
26 | +} | |
27 | + | |
28 | +/* | |
29 | + * xf86ValidateFontPath -- | |
30 | + * Validates the user-specified font path. Each element that | |
31 | + * begins with a '/' is checked to make sure the directory exists. | |
32 | + * If the directory exists, the existence of a file named 'fonts.dir' | |
33 | + * is checked. If either check fails, an error is printed and the | |
34 | + * element is removed from the font path. | |
35 | + */ | |
36 | +#define DIR_FILE "/fonts.dir" | |
37 | +#define CHECK_TYPE(mode, type) ((S_IFMT & (mode)) == (type)) | |
38 | +static char * | |
39 | +xf86ValidateFontPath(path) | |
40 | + char *path; | |
41 | +{ | |
42 | + char *tmp_path, *out_pnt, *path_elem, *next, *p1, *dir_elem; | |
43 | + struct stat stat_buf; | |
44 | + int flag; | |
45 | + int dirlen; | |
46 | + | |
47 | + tmp_path = (char *)calloc(1,strlen(path)+1); | |
48 | + out_pnt = tmp_path; | |
49 | + path_elem = NULL; | |
50 | + next = path; | |
51 | + while (next != NULL) { | |
52 | + path_elem = xf86GetPathElem(&next); | |
53 | +#ifndef __EMX__ | |
54 | + if (*path_elem == '/') { | |
55 | + dir_elem = (char *)calloc(1, strlen(path_elem) + 1); | |
56 | + if ((p1 = strchr(path_elem, ':')) != 0) | |
57 | +#else | |
58 | + /* OS/2 must prepend X11ROOT */ | |
59 | + if (*path_elem == '/') { | |
60 | + path_elem = (char*)__XOS2RedirRoot(path_elem); | |
61 | + dir_elem = (char*)calloc(1, strlen(path_elem) + 1); | |
62 | + if (p1 = strchr(path_elem+2, ':')) | |
63 | +#endif | |
64 | + dirlen = p1 - path_elem; | |
65 | + else | |
66 | + dirlen = strlen(path_elem); | |
67 | + strncpy(dir_elem, path_elem, dirlen); | |
68 | + dir_elem[dirlen] = '\0'; | |
69 | + flag = stat(dir_elem, &stat_buf); | |
70 | + if (flag == 0) | |
71 | + if (!CHECK_TYPE(stat_buf.st_mode, S_IFDIR)) | |
72 | + flag = -1; | |
73 | + if (flag != 0) { | |
74 | + printf("warning!\n"); | |
75 | + ErrorF("Warning: The directory \"%s\" does not exist.\n", dir_elem); | |
76 | + ErrorF(" Entry deleted from font path.\n"); | |
77 | + continue; | |
78 | + } | |
79 | + else { | |
80 | + p1 = (char *)malloc(strlen(dir_elem)+strlen(DIR_FILE)+1); | |
81 | + strcpy(p1, dir_elem); | |
82 | + strcat(p1, DIR_FILE); | |
83 | + flag = stat(p1, &stat_buf); | |
84 | + if (flag == 0) | |
85 | + if (!CHECK_TYPE(stat_buf.st_mode, S_IFREG)) | |
86 | + flag = -1; | |
87 | +#ifndef __EMX__ | |
88 | + free(p1); | |
89 | +#endif | |
90 | + if (flag != 0) { | |
91 | + ErrorF("Warning: 'fonts.dir' not found (or not valid) in \"%s\".\n", | |
92 | + dir_elem); | |
93 | + ErrorF(" Entry deleted from font path.\n"); | |
94 | + ErrorF(" (Run 'mkfontdir' on \"%s\").\n", dir_elem); | |
95 | + continue; | |
96 | + } | |
97 | + } | |
98 | + free(dir_elem); | |
99 | + } | |
100 | + | |
101 | + /* | |
102 | + * Either an OK directory, or a font server name. So add it to | |
103 | + * the path. | |
104 | + */ | |
105 | + if (out_pnt != tmp_path) | |
106 | + *out_pnt++ = ','; | |
107 | + strcat(out_pnt, path_elem); | |
108 | + out_pnt += strlen(path_elem); | |
109 | + } | |
110 | + return(tmp_path); | |
111 | +} | |
112 | + | |
113 | +/* | |
114 | * note that the font wakeup queue is not refcounted. this is because | |
115 | * an fpe needs to be added when it's inited, and removed when it's finally | |
116 | * freed, in order to handle any data that isn't requested, like FS events. | |
340ec576 | 117 | @@ -734,8 +841,12 @@ |
505397d5 | 118 | *end, |
119 | *p; | |
120 | int err; | |
121 | + char *fixedpath; | |
122 | + | |
123 | + fixedpath = xf86ValidateFontPath(str); | |
124 | ||
125 | - len = strlen(str) + 1; | |
126 | + len = strlen(fixedpath) + 1; | |
127 | + str = fixedpath; | |
128 | paths = p = (char *) ALLOCATE_LOCAL(len); | |
129 | npaths = 0; | |
130 | ||
340ec576 | 131 | @@ -755,6 +866,7 @@ |
505397d5 | 132 | |
133 | err = set_font_path_elements(npaths, paths, badpath); | |
134 | ||
135 | + free(fixedpath); | |
136 | DEALLOCATE_LOCAL(paths); | |
137 | ||
138 | return err; | |
340ec576 | 139 | --- xc/programs/xfs/difs/main.c.xfsredhat Sun Mar 7 15:50:25 1999 |
140 | +++ xc/programs/xfs/difs/main.c Tue Mar 14 12:10:39 2000 | |
141 | @@ -56,12 +56,18 @@ | |
142 | #include "dispatch.h" | |
143 | #include "extentst.h" | |
144 | #include "difs.h" | |
505397d5 | 145 | +#include <unistd.h> |
340ec576 | 146 | +#include <pwd.h> |
147 | +#include <sys/types.h> | |
505397d5 | 148 | |
149 | char *ConnectionInfo; | |
150 | int ConnInfoLen; | |
340ec576 | 151 | |
152 | Cache serverCache; | |
153 | ||
154 | +int droppriv; /* whether or not to drop root privileges at startup */ | |
155 | +int becomeDaemon; /* whether or not to become a daemon */ | |
156 | + | |
157 | #ifndef DEFAULT_CONFIG_FILE | |
158 | #define DEFAULT_CONFIG_FILE "/usr/lib/X11/fs/config" | |
159 | #endif | |
160 | @@ -80,15 +86,43 @@ | |
161 | main(int argc, char *argv[]) | |
162 | { | |
163 | int i; | |
164 | + struct passwd *pwent; | |
165 | ||
166 | argcGlobal = argc; | |
167 | argvGlobal = argv; | |
168 | + droppriv = 0; | |
169 | + becomeDaemon = 0; | |
170 | ||
171 | configfilename = DEFAULT_CONFIG_FILE; | |
172 | ||
173 | /* init stuff */ | |
174 | ProcessCmdLine(argc, argv); | |
175 | InitErrors(); | |
176 | + | |
177 | + /* become xfs user, if possible */ | |
178 | + if ((geteuid() == 0) && droppriv) { | |
179 | + pwent = getpwnam("xfs"); | |
180 | + if (pwent) { | |
181 | + if (setgid(pwent->pw_gid)) { | |
182 | + ErrorF("fatal: couldn't set groupid to xfs user's group\n"); | |
183 | + exit(1); | |
184 | + } | |
185 | + | |
186 | + if (setgroups(0, 0)) { | |
187 | + ErrorF("fatal: couldn't drop supplementary groups\n"); | |
188 | + exit(1); | |
189 | + } | |
190 | + | |
191 | + if (setuid(pwent->pw_uid)) { | |
192 | + ErrorF("fatal: couldn't set userid to xfs user\n"); | |
193 | + exit(1); | |
194 | + } | |
195 | + } | |
196 | + } else if (droppriv) { | |
197 | + ErrorF("fatal: droppriv flag specified, but xfs not run as root\n"); | |
198 | + exit(1); | |
199 | + } | |
200 | + | |
201 | /* | |
202 | * do this first thing, to get any options that only take effect at | |
203 | * startup time. it is erad again each time the server resets | |
204 | @@ -97,6 +131,10 @@ | |
505397d5 | 205 | ErrorF("fatal: couldn't read config file\n"); |
206 | exit(1); | |
207 | } | |
208 | + | |
340ec576 | 209 | + /* become a daemon if explicitly requested to do so. */ |
210 | + if (becomeDaemon) | |
211 | + daemon(0, 0); | |
505397d5 | 212 | |
213 | while (1) { | |
214 | serverGeneration++; | |
340ec576 | 215 | --- xc/programs/xfs/os/utils.c.xfsredhat Sun Mar 7 15:50:30 1999 |
216 | +++ xc/programs/xfs/os/utils.c Tue Mar 14 12:10:39 2000 | |
217 | @@ -91,6 +91,8 @@ | |
218 | #endif | |
219 | ||
220 | extern char *configfilename; | |
221 | +extern int droppriv; /* whether or not to drop root privileges */ | |
222 | +extern int becomeDaemon; /* whether to become a daemon or not */ | |
223 | char *progname; | |
224 | Bool CloneSelf; | |
225 | ||
226 | @@ -189,7 +191,7 @@ | |
227 | static void | |
228 | usage(void) | |
229 | { | |
230 | - fprintf(stderr, "usage: %s [-config config_file] [-port tcp_port]\n", | |
231 | + fprintf(stderr, "usage: %s [-config config_file] [-port tcp_port] [-droppriv] [-daemon]\n", | |
232 | progname); | |
233 | exit(1); | |
234 | } | |
235 | @@ -293,6 +295,10 @@ | |
236 | ProcessLSoption (argv[++i]); | |
237 | else | |
238 | usage(); | |
239 | + } else if (!strcmp(argv[i], "-droppriv")) { | |
240 | + droppriv = 1; | |
241 | + } else if (!strcmp(argv[i], "-daemon")) { | |
242 | + becomeDaemon = 1; | |
243 | } else if (!strcmp(argv[i], "-cf") || !strcmp(argv[i], "-config")) { | |
244 | if (argv[i + 1]) | |
245 | configfilename = argv[++i]; | |
246 | --- xc/programs/xfs/os/Imakefile.xfsredhat Sun Feb 13 08:54:42 2000 | |
247 | +++ xc/programs/xfs/os/Imakefile Tue Mar 14 12:10:39 2000 | |
248 | @@ -23,7 +23,7 @@ | |
249 | SOCK_DEFINES = -DBSD44SOCKETS | |
250 | #endif | |
251 | ||
252 | -/* ERROR_DEFINES = -DUSE_SYSLOG */ | |
253 | +ERROR_DEFINES = -DUSE_SYSLOG | |
254 | ||
255 | OS_DEFINES = ServerOSDefines | |
256 | ||
257 | --- xc/programs/xfs/os/error.c.xfsredhat Sun Oct 25 14:59:57 1998 | |
258 | +++ xc/programs/xfs/os/error.c Tue Mar 14 13:29:26 2000 | |
259 | @@ -76,6 +76,7 @@ | |
260 | ||
261 | Bool UseSyslog; | |
262 | char ErrorFile[PATH_MAX]; | |
263 | +int log_open = 0; | |
264 | ||
265 | static void | |
266 | abort_server(void) | |
267 | @@ -142,17 +143,21 @@ | |
268 | ||
269 | #ifdef USE_SYSLOG | |
270 | if (UseSyslog) { | |
271 | - syslog(LOG_NOTICE, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9); | |
272 | + va_list args; | |
273 | + va_start(args, f); | |
274 | + syslog(LOG_NOTICE, f, args); | |
275 | + va_end(args); | |
276 | return; | |
277 | } | |
278 | #endif | |
279 | - | |
280 | + { | |
281 | /* XXX should Notices just be ignored if not using syslog? */ | |
282 | va_list args; | |
283 | va_start(args, f); | |
284 | fprintf(stderr, "%s notice: ", progname); | |
285 | vfprintf(stderr, f, args); | |
286 | va_end(args); | |
287 | + } | |
288 | } | |
289 | ||
290 | /* | |
291 | @@ -164,15 +169,20 @@ | |
292 | { | |
293 | #ifdef USE_SYSLOG | |
294 | if (UseSyslog) { | |
295 | - syslog(LOG_ERR, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9); | |
296 | + va_list args; | |
297 | + va_start(args, f); | |
298 | + syslog(LOG_ERR, f, args); | |
299 | + va_end(args); | |
300 | return; | |
301 | } | |
302 | #endif | |
303 | + { | |
304 | va_list args; | |
305 | va_start(args, f); | |
306 | fprintf(stderr, "%s error: ", progname); | |
307 | vfprintf(stderr, f, args); | |
308 | va_end(args); | |
309 | + } | |
310 | } | |
311 | ||
312 | /* VARARGS1 */ |