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).
55 /* View/edit this file with tab stops set to 4 */
57 #ifdef HAVE_XORG_CONFIG_H
58 #include <xorg-config.h>
61 #include "xf86Parser.h"
62 #include "xf86tokens.h"
63 #include "Configint.h"
66 #include <sys/types.h>
71 #if ((defined(sun) && !defined(SVR4)) || defined(macII)) && !defined(__GLIBC__)
73 extern char *sys_errlist
[];
76 (((n) >= 0 && (n) < sys_nerr) ? sys_errlist[n] : "unknown error")
80 #if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
81 #define HAS_SAVED_IDS_AND_SETEUID
88 #define doWriteConfigFile xf86writeConfigFile
95 doWriteConfigFile (const char *filename
, XF86ConfigPtr cptr
)
99 if ((cf
= fopen (filename
, "w")) == NULL
)
104 if (cptr
->conf_comment
)
105 fprintf (cf
, "%s\n", cptr
->conf_comment
);
107 xf86printLayoutSection (cf
, cptr
->conf_layout_lst
);
109 if (cptr
->conf_files
!= NULL
)
111 fprintf (cf
, "Section \"Files\"\n");
112 xf86printFileSection (cf
, cptr
->conf_files
);
113 fprintf (cf
, "EndSection\n\n");
116 if (cptr
->conf_modules
!= NULL
)
118 fprintf (cf
, "Section \"Module\"\n");
119 xf86printModuleSection (cf
, cptr
->conf_modules
);
120 fprintf (cf
, "EndSection\n\n");
123 xf86printVendorSection (cf
, cptr
->conf_vendor_lst
);
125 xf86printServerFlagsSection (cf
, cptr
->conf_flags
);
127 xf86printInputSection (cf
, cptr
->conf_input_lst
);
129 xf86printVideoAdaptorSection (cf
, cptr
->conf_videoadaptor_lst
);
131 xf86printModesSection (cf
, cptr
->conf_modes_lst
);
133 xf86printMonitorSection (cf
, cptr
->conf_monitor_lst
);
135 xf86printDeviceSection (cf
, cptr
->conf_device_lst
);
137 xf86printScreenSection (cf
, cptr
->conf_screen_lst
);
139 xf86printDRISection (cf
, cptr
->conf_dri
);
141 xf86printExtensionsSection (cf
, cptr
->conf_extensions
);
150 xf86writeConfigFile (const char *filename
, XF86ConfigPtr cptr
)
154 #if !defined(HAS_SAVED_IDS_AND_SETEUID)
162 if (getuid() != geteuid())
165 #if !defined(HAS_SAVED_IDS_AND_SETEUID)
166 /* Need to fork to change ruid without loosing euid */
168 csig
= signal(SIGCHLD
, SIG_DFL
);
170 switch ((pid
= fork()))
173 ErrorF("xf86writeConfigFile(): fork failed (%s)\n",
177 if (setuid(getuid()) == -1)
178 FatalError("xf86writeConfigFile(): "
179 "setuid failed(%s)\n",
181 ret
= doWriteConfigFile(filename
, cptr
);
184 default: /* parent */
187 p
= waitpid(pid
, &status
, 0);
188 } while (p
== -1 && errno
== EINTR
);
191 signal(SIGCHLD
, csig
);
193 if (p
!= -1 && WIFEXITED(status
) && WEXITSTATUS(status
) == 0)
194 return 1; /* success */
198 #else /* HAS_SAVED_IDS_AND_SETEUID */
203 if (seteuid(ruid
) == -1)
205 ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n",
206 ruid
, strerror(errno
));
209 ret
= doWriteConfigFile(filename
, cptr
);
211 if (seteuid(euid
) == -1)
213 ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n",
214 euid
, strerror(errno
));
218 #endif /* HAS_SAVED_IDS_AND_SETEUID */
223 return doWriteConfigFile(filename
, cptr
);
227 #endif /* !HAS_NO_UIDS */