]>
Commit | Line | Data |
---|---|---|
1d5726dc JR |
1 | diff -Nur XFree86-4.0.2.org/xc/programs/xfs/difs/fonts.c XFree86-4.0.2/xc/programs/xfs/difs/fonts.c |
2 | --- XFree86-4.0.2.org/xc/programs/xfs/difs/fonts.c Thu Dec 14 20:54:53 2000 | |
3 | +++ XFree86-4.0.2/xc/programs/xfs/difs/fonts.c Thu Dec 21 09:26:42 2000 | |
4 | @@ -108,6 +108,113 @@ | |
5 | } | |
6 | ||
7 | /* | |
8 | + * xf86GetPathElem -- | |
9 | + * Extract a single element from the font path string starting at | |
10 | + * pnt. The font path element will be returned, and pnt will be | |
11 | + * updated to point to the start of the next element, or set to | |
12 | + * NULL if there are no more. | |
13 | + */ | |
14 | +char * | |
15 | +xf86GetPathElem(pnt) | |
16 | + char **pnt; | |
17 | +{ | |
18 | + char *p1; | |
19 | + | |
20 | + p1 = *pnt; | |
21 | + *pnt = index(*pnt, ','); | |
22 | + if (*pnt != NULL) { | |
23 | + **pnt = '\0'; | |
24 | + *pnt += 1; | |
25 | + } | |
26 | + return(p1); | |
27 | +} | |
28 | + | |
29 | +/* | |
30 | + * xf86ValidateFontPath -- | |
31 | + * Validates the user-specified font path. Each element that | |
32 | + * begins with a '/' is checked to make sure the directory exists. | |
33 | + * If the directory exists, the existence of a file named 'fonts.dir' | |
34 | + * is checked. If either check fails, an error is printed and the | |
35 | + * element is removed from the font path. | |
36 | + */ | |
37 | +#define DIR_FILE "/fonts.dir" | |
38 | +#define CHECK_TYPE(mode, type) ((S_IFMT & (mode)) == (type)) | |
39 | +static char * | |
40 | +xf86ValidateFontPath(path) | |
41 | + char *path; | |
42 | +{ | |
43 | + char *tmp_path, *out_pnt, *path_elem, *next, *p1, *dir_elem; | |
44 | + struct stat stat_buf; | |
45 | + int flag; | |
46 | + int dirlen; | |
47 | + | |
48 | + tmp_path = (char *)calloc(1,strlen(path)+1); | |
49 | + out_pnt = tmp_path; | |
50 | + path_elem = NULL; | |
51 | + next = path; | |
52 | + while (next != NULL) { | |
53 | + path_elem = xf86GetPathElem(&next); | |
54 | +#ifndef __EMX__ | |
55 | + if (*path_elem == '/') { | |
56 | + dir_elem = (char *)calloc(1, strlen(path_elem) + 1); | |
57 | + if ((p1 = strchr(path_elem, ':')) != 0) | |
58 | +#else | |
59 | + /* OS/2 must prepend X11ROOT */ | |
60 | + if (*path_elem == '/') { | |
61 | + path_elem = (char*)__XOS2RedirRoot(path_elem); | |
62 | + dir_elem = (char*)calloc(1, strlen(path_elem) + 1); | |
63 | + if (p1 = strchr(path_elem+2, ':')) | |
64 | +#endif | |
65 | + dirlen = p1 - path_elem; | |
66 | + else | |
67 | + dirlen = strlen(path_elem); | |
68 | + strncpy(dir_elem, path_elem, dirlen); | |
69 | + dir_elem[dirlen] = '\0'; | |
70 | + flag = stat(dir_elem, &stat_buf); | |
71 | + if (flag == 0) | |
72 | + if (!CHECK_TYPE(stat_buf.st_mode, S_IFDIR)) | |
73 | + flag = -1; | |
74 | + if (flag != 0) { | |
75 | + printf("warning!\n"); | |
76 | + ErrorF("Warning: The directory \"%s\" does not exist.\n", dir_elem); | |
77 | + ErrorF(" Entry deleted from font path.\n"); | |
78 | + continue; | |
79 | + } | |
80 | + else { | |
81 | + p1 = (char *)malloc(strlen(dir_elem)+strlen(DIR_FILE)+1); | |
82 | + strcpy(p1, dir_elem); | |
83 | + strcat(p1, DIR_FILE); | |
84 | + flag = stat(p1, &stat_buf); | |
85 | + if (flag == 0) | |
86 | + if (!CHECK_TYPE(stat_buf.st_mode, S_IFREG)) | |
87 | + flag = -1; | |
88 | +#ifndef __EMX__ | |
89 | + free(p1); | |
90 | +#endif | |
91 | + if (flag != 0) { | |
92 | + ErrorF("Warning: 'fonts.dir' not found (or not valid) in \"%s\".\n", | |
93 | + dir_elem); | |
94 | + ErrorF(" Entry deleted from font path.\n"); | |
95 | + ErrorF(" (Run 'mkfontdir' on \"%s\").\n", dir_elem); | |
96 | + continue; | |
97 | + } | |
98 | + } | |
99 | + free(dir_elem); | |
100 | + } | |
101 | + | |
102 | + /* | |
103 | + * Either an OK directory, or a font server name. So add it to | |
104 | + * the path. | |
105 | + */ | |
106 | + if (out_pnt != tmp_path) | |
107 | + *out_pnt++ = ','; | |
108 | + strcat(out_pnt, path_elem); | |
109 | + out_pnt += strlen(path_elem); | |
110 | + } | |
111 | + return(tmp_path); | |
112 | +} | |
113 | + | |
114 | +/* | |
115 | * note that the font wakeup queue is not refcounted. this is because | |
116 | * an fpe needs to be added when it's inited, and removed when it's finally | |
117 | * freed, in order to handle any data that isn't requested, like FS events. | |
118 | @@ -744,8 +851,12 @@ | |
119 | *end, | |
120 | *p; | |
121 | int err; | |
122 | + char *fixedpath; | |
123 | + | |
124 | + fixedpath = xf86ValidateFontPath(str); | |
125 | ||
126 | - len = strlen(str) + 1; | |
127 | + len = strlen(fixedpath) + 1; | |
128 | + str = fixedpath; | |
129 | paths = p = (char *) ALLOCATE_LOCAL(len); | |
130 | npaths = 0; | |
131 | ||
132 | @@ -765,6 +876,7 @@ | |
133 | ||
134 | err = set_font_path_elements(npaths, paths, badpath); | |
135 | ||
136 | + free(fixedpath); | |
137 | DEALLOCATE_LOCAL(paths); | |
138 | ||
139 | return err; | |
140 | diff -Nur XFree86-4.0.2.org/xc/programs/xfs/difs/main.c XFree86-4.0.2/xc/programs/xfs/difs/main.c | |
141 | --- XFree86-4.0.2.org/xc/programs/xfs/difs/main.c Sat Dec 9 05:02:14 2000 | |
142 | +++ XFree86-4.0.2/xc/programs/xfs/difs/main.c Thu Dec 21 09:40:53 2000 | |
143 | @@ -56,12 +56,18 @@ | |
144 | #include "dispatch.h" | |
145 | #include "extentst.h" | |
146 | #include "difs.h" | |
147 | +#include <unistd.h> | |
148 | +#include <pwd.h> | |
149 | +#include <sys/types.h> | |
150 | ||
151 | char *ConnectionInfo; | |
152 | int ConnInfoLen; | |
153 | ||
154 | Cache serverCache; | |
155 | ||
156 | +int droppriv; /* whether or not to drop root privileges at startup */ | |
157 | +int becomeDaemon; /* whether or not to become a daemon */ | |
158 | + | |
159 | #ifndef DEFAULT_CONFIG_FILE | |
160 | #define DEFAULT_CONFIG_FILE "/usr/lib/X11/fs/config" | |
161 | #endif | |
162 | @@ -84,13 +90,39 @@ | |
163 | ||
164 | argcGlobal = argc; | |
165 | argvGlobal = argv; | |
166 | - | |
167 | + droppriv = 0; | |
168 | + becomeDaemon =0; | |
169 | + | |
170 | configfilename = DEFAULT_CONFIG_FILE; | |
171 | ||
172 | /* init stuff */ | |
173 | ProcessCmdLine(argc, argv); | |
174 | InitErrors(); | |
175 | ||
176 | + /* become xfs user, if possible */ | |
177 | + if ((geteuid() == 0) && droppriv) { | |
178 | + pwent = getpwnam("xfs"); | |
179 | + if (pwent) { | |
180 | + if (setgid(pwent->pw_gid)) { | |
181 | + ErrorF("fatal: couldn't set groupid to xfs user's group\n"); | |
182 | + exit(1); | |
183 | + } | |
184 | + | |
185 | + if (setgroups(0, 0)) { | |
186 | + ErrorF("fatal: couldn't drop supplementary groups\n"); | |
187 | + exit(1); | |
188 | + } | |
189 | + | |
190 | + if (setuid(pwent->pw_uid)) { | |
191 | + ErrorF("fatal: couldn't set userid to xfs user\n"); | |
192 | + exit(1); | |
193 | + } | |
194 | + } | |
195 | + } else if (droppriv) { | |
196 | + ErrorF("fatal: droppriv flag specified, but xfs not run as root\n"); | |
197 | + exit(1); | |
198 | + } | |
199 | + | |
200 | /* | |
201 | * do this first thing, to get any options that only take effect at | |
202 | * startup time. it is read again each time the server resets | |
203 | @@ -99,6 +131,10 @@ | |
204 | ErrorF("fatal: couldn't read config file\n"); | |
205 | exit(1); | |
206 | } | |
207 | + | |
208 | + /* become a daemon if explicitly requested to do so. */ | |
209 | + if (becomeDaemon) | |
210 | + daemon(0, 0); | |
211 | ||
212 | /* make sure at least world write access is disabled */ | |
213 | if (((oldumask = umask(022)) & 002) == 002) | |
214 | diff -Nur XFree86-4.0.2.org/xc/programs/xfs/os/error.c XFree86-4.0.2/xc/programs/xfs/os/error.c | |
215 | --- XFree86-4.0.2.org/xc/programs/xfs/os/error.c Tue Dec 5 01:59:41 2000 | |
216 | +++ XFree86-4.0.2/xc/programs/xfs/os/error.c Thu Dec 21 09:26:42 2000 | |
217 | @@ -81,6 +81,7 @@ | |
218 | Bool log_open = FALSE; | |
219 | #endif | |
220 | char ErrorFile[PATH_MAX]; | |
221 | +int log_open = 0; | |
222 | ||
223 | static void | |
224 | abort_server(void) | |
225 | diff -Nur XFree86-4.0.2.org/xc/programs/xfs/os/utils.c XFree86-4.0.2/xc/programs/xfs/os/utils.c | |
226 | --- XFree86-4.0.2.org/xc/programs/xfs/os/utils.c Tue Dec 5 01:59:41 2000 | |
227 | +++ XFree86-4.0.2/xc/programs/xfs/os/utils.c Thu Dec 21 09:26:42 2000 | |
228 | @@ -317,6 +317,10 @@ | |
229 | userId = argv[++i]; | |
230 | else | |
231 | usage(); | |
232 | + } else if (!strcmp(argv[i], "-droppriv")) { | |
233 | + droppriv = 1; | |
234 | + } else if (!strcmp(argv[i], "-daemon")) { | |
235 | + becomeDaemon = 1; | |
236 | } else if (!strcmp(argv[i], "-cf") || !strcmp(argv[i], "-config")) { | |
237 | if (argv[i + 1]) | |
238 | configfilename = argv[++i]; |