26739b9330874577b6dcabda14a3a939ad2d658d
2 * Copyright (c) 1997 Metro Link Incorporated
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * Except as contained in this notice, the name of the Metro Link shall not be
23 * used in advertising or otherwise to promote the sale, use or other dealings
24 * in this Software without prior written authorization from Metro Link.
28 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
30 * Permission is hereby granted, free of charge, to any person obtaining a
31 * copy of this software and associated documentation files (the "Software"),
32 * to deal in the Software without restriction, including without limitation
33 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
34 * and/or sell copies of the Software, and to permit persons to whom the
35 * Software is furnished to do so, subject to the following conditions:
37 * The above copyright notice and this permission notice shall be included in
38 * all copies or substantial portions of the Software.
40 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
43 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
44 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
45 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
46 * OTHER DEALINGS IN THE SOFTWARE.
48 * Except as contained in this notice, the name of the copyright holder(s)
49 * and author(s) shall not be used in advertising or otherwise to promote
50 * the sale, use or other dealings in this Software without prior written
51 * authorization from the copyright holder(s) and author(s).
54 #ifdef HAVE_XORG_CONFIG_H
55 #include <xorg-config.h>
59 #include "xf86Parser.h"
60 #include "xf86tokens.h"
61 #include "Configint.h"
64 #include <sys/types.h>
69 #if defined(HAVE_SETEUID) && defined(_POSIX_SAVED_IDS) && _POSIX_SAVED_IDS > 0
70 #define HAS_SAVED_IDS_AND_SETEUID
77 #define doWriteConfigFile xf86writeConfigFile
84 doWriteConfigFile(const char *filename
, XF86ConfigPtr cptr
)
88 if ((cf
= fopen(filename
, "w")) == NULL
) {
92 if (cptr
->conf_comment
)
93 fprintf(cf
, "%s\n", cptr
->conf_comment
);
95 xf86printLayoutSection(cf
, cptr
->conf_layout_lst
);
97 if (cptr
->conf_files
!= NULL
) {
98 fprintf(cf
, "Section \"Files\"\n");
99 xf86printFileSection(cf
, cptr
->conf_files
);
100 fprintf(cf
, "EndSection\n\n");
103 if (cptr
->conf_modules
!= NULL
) {
104 fprintf(cf
, "Section \"Module\"\n");
105 xf86printModuleSection(cf
, cptr
->conf_modules
);
106 fprintf(cf
, "EndSection\n\n");
109 xf86printVendorSection(cf
, cptr
->conf_vendor_lst
);
111 xf86printServerFlagsSection(cf
, cptr
->conf_flags
);
113 xf86printInputSection(cf
, cptr
->conf_input_lst
);
115 xf86printInputClassSection(cf
, cptr
->conf_inputclass_lst
);
117 xf86printVideoAdaptorSection(cf
, cptr
->conf_videoadaptor_lst
);
119 xf86printModesSection(cf
, cptr
->conf_modes_lst
);
121 xf86printMonitorSection(cf
, cptr
->conf_monitor_lst
);
123 xf86printDeviceSection(cf
, cptr
->conf_device_lst
);
125 xf86printScreenSection(cf
, cptr
->conf_screen_lst
);
127 xf86printDRISection(cf
, cptr
->conf_dri
);
129 xf86printExtensionsSection(cf
, cptr
->conf_extensions
);
138 xf86writeConfigFile(const char *filename
, XF86ConfigPtr cptr
)
142 #if !defined(HAS_SAVED_IDS_AND_SETEUID)
150 if (getuid() != geteuid()) {
152 #if !defined(HAS_SAVED_IDS_AND_SETEUID)
153 /* Need to fork to change ruid without loosing euid */
154 csig
= signal(SIGCHLD
, SIG_DFL
);
155 switch ((pid
= fork())) {
157 ErrorF("xf86writeConfigFile(): fork failed (%s)\n",
161 if (setuid(getuid()) == -1)
162 FatalError("xf86writeConfigFile(): "
163 "setuid failed(%s)\n", strerror(errno
));
164 ret
= doWriteConfigFile(filename
, cptr
);
167 default: /* parent */
169 p
= waitpid(pid
, &status
, 0);
170 } while (p
== -1 && errno
== EINTR
);
172 signal(SIGCHLD
, csig
);
173 if (p
!= -1 && WIFEXITED(status
) && WEXITSTATUS(status
) == 0)
174 return 1; /* success */
178 #else /* HAS_SAVED_IDS_AND_SETEUID */
183 if (seteuid(ruid
) == -1) {
184 ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n",
185 ruid
, strerror(errno
));
188 ret
= doWriteConfigFile(filename
, cptr
);
190 if (seteuid(euid
) == -1) {
191 ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n",
192 euid
, strerror(errno
));
196 #endif /* HAS_SAVED_IDS_AND_SETEUID */
200 return doWriteConfigFile(filename
, cptr
);
204 #endif /* !HAS_NO_UIDS */