1
/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/write.c,v 1.18 2003/08/24 17:37:08 dawes Exp $ */
4
* Copyright (c) 1997 Metro Link Incorporated
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the "Software"),
8
* to deal in the Software without restriction, including without limitation
9
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
* and/or sell copies of the Software, and to permit persons to whom the
11
* Software is furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
* Except as contained in this notice, the name of the Metro Link shall not be
25
* used in advertising or otherwise to promote the sale, use or other dealings
26
* in this Software without prior written authorization from Metro Link.
30
* Copyright (c) 1997-2003 by The XFree86 Project, Inc.
32
* Permission is hereby granted, free of charge, to any person obtaining a
33
* copy of this software and associated documentation files (the "Software"),
34
* to deal in the Software without restriction, including without limitation
35
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
36
* and/or sell copies of the Software, and to permit persons to whom the
37
* Software is furnished to do so, subject to the following conditions:
39
* The above copyright notice and this permission notice shall be included in
40
* all copies or substantial portions of the Software.
42
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
45
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
46
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
47
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
48
* OTHER DEALINGS IN THE SOFTWARE.
50
* Except as contained in this notice, the name of the copyright holder(s)
51
* and author(s) shall not be used in advertising or otherwise to promote
52
* the sale, use or other dealings in this Software without prior written
53
* authorization from the copyright holder(s) and author(s).
57
/* View/edit this file with tab stops set to 4 */
59
#ifdef HAVE_XORG_CONFIG_H
60
#include <xorg-config.h>
63
#include "xf86Parser.h"
64
#include "xf86tokens.h"
65
#include "Configint.h"
68
#include <sys/types.h>
73
#if ((defined(sun) && !defined(SVR4)) || defined(macII)) && !defined(__GLIBC__)
75
extern char *sys_errlist[];
78
(((n) >= 0 && (n) < sys_nerr) ? sys_errlist[n] : "unknown error")
82
#if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
83
#define HAS_SAVED_IDS_AND_SETEUID
85
#if defined(__UNIXOS2__) || defined(WIN32)
90
#define doWriteConfigFile xf86writeConfigFile
97
doWriteConfigFile (const char *filename, XF86ConfigPtr cptr)
101
if ((cf = fopen (filename, "w")) == NULL)
106
if (cptr->conf_comment)
107
fprintf (cf, "%s\n", cptr->conf_comment);
109
xf86printLayoutSection (cf, cptr->conf_layout_lst);
111
fprintf (cf, "Section \"Files\"\n");
112
xf86printFileSection (cf, cptr->conf_files);
113
fprintf (cf, "EndSection\n\n");
115
fprintf (cf, "Section \"Module\"\n");
116
xf86printModuleSection (cf, cptr->conf_modules);
117
fprintf (cf, "EndSection\n\n");
119
xf86printVendorSection (cf, cptr->conf_vendor_lst);
121
xf86printServerFlagsSection (cf, cptr->conf_flags);
123
xf86printInputSection (cf, cptr->conf_input_lst);
125
xf86printVideoAdaptorSection (cf, cptr->conf_videoadaptor_lst);
127
xf86printModesSection (cf, cptr->conf_modes_lst);
129
xf86printMonitorSection (cf, cptr->conf_monitor_lst);
131
xf86printDeviceSection (cf, cptr->conf_device_lst);
133
xf86printScreenSection (cf, cptr->conf_screen_lst);
135
xf86printDRISection (cf, cptr->conf_dri);
137
xf86printExtensionsSection (cf, cptr->conf_extensions);
146
xf86writeConfigFile (const char *filename, XF86ConfigPtr cptr)
150
#if !defined(HAS_SAVED_IDS_AND_SETEUID)
158
if (getuid() != geteuid())
161
#if !defined(HAS_SAVED_IDS_AND_SETEUID)
162
/* Need to fork to change ruid without loosing euid */
164
csig = signal(SIGCHLD, SIG_DFL);
166
switch ((pid = fork()))
169
ErrorF("xf86writeConfigFile(): fork failed (%s)\n",
174
ret = doWriteConfigFile(filename, cptr);
177
default: /* parent */
180
p = waitpid(pid, &status, 0);
181
} while (p == -1 && errno == EINTR);
184
signal(SIGCHLD, csig);
186
if (p != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0)
187
return 1; /* success */
191
#else /* HAS_SAVED_IDS_AND_SETEUID */
196
if (seteuid(ruid) == -1)
198
ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n",
199
ruid, strerror(errno));
202
ret = doWriteConfigFile(filename, cptr);
204
if (seteuid(euid) == -1)
206
ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n",
207
euid, strerror(errno));
211
#endif /* HAS_SAVED_IDS_AND_SETEUID */
216
return doWriteConfigFile(filename, cptr);
220
#endif /* !HAS_NO_UIDS */