1
/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/write.c,v 1.17 2002/09/17 18:54:16 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
/* View/edit this file with tab stops set to 4 */
32
#include "xf86Parser.h"
33
#include "xf86tokens.h"
34
#include "Configint.h"
37
#include <sys/types.h>
42
#if ((defined(sun) && !defined(SVR4)) || defined(macII)) && !defined(__GLIBC__)
44
extern char *sys_errlist[];
47
(((n) >= 0 && (n) < sys_nerr) ? sys_errlist[n] : "unknown error")
51
#if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
52
#define HAS_SAVED_IDS_AND_SETEUID
54
#if defined(__UNIXOS2__) || defined(WIN32)
59
#define doWriteConfigFile xf86writeConfigFile
66
doWriteConfigFile (const char *filename, XF86ConfigPtr cptr)
70
if ((cf = fopen (filename, "w")) == NULL)
75
if (cptr->conf_comment)
76
fprintf (cf, "%s\n", cptr->conf_comment);
78
xf86printLayoutSection (cf, cptr->conf_layout_lst);
80
fprintf (cf, "Section \"Files\"\n");
81
xf86printFileSection (cf, cptr->conf_files);
82
fprintf (cf, "EndSection\n\n");
84
fprintf (cf, "Section \"Module\"\n");
85
xf86printModuleSection (cf, cptr->conf_modules);
86
fprintf (cf, "EndSection\n\n");
88
xf86printVendorSection (cf, cptr->conf_vendor_lst);
90
xf86printServerFlagsSection (cf, cptr->conf_flags);
92
xf86printInputSection (cf, cptr->conf_input_lst);
94
xf86printVideoAdaptorSection (cf, cptr->conf_videoadaptor_lst);
96
xf86printModesSection (cf, cptr->conf_modes_lst);
98
xf86printMonitorSection (cf, cptr->conf_monitor_lst);
100
xf86printDeviceSection (cf, cptr->conf_device_lst);
102
xf86printScreenSection (cf, cptr->conf_screen_lst);
104
xf86printDRISection (cf, cptr->conf_dri);
113
xf86writeConfigFile (const char *filename, XF86ConfigPtr cptr)
117
#if !defined(HAS_SAVED_IDS_AND_SETEUID)
125
if (getuid() != geteuid())
128
#if !defined(HAS_SAVED_IDS_AND_SETEUID)
129
/* Need to fork to change ruid without loosing euid */
131
csig = signal(SIGCHLD, SIG_DFL);
133
switch ((pid = fork()))
136
ErrorF("xf86writeConfigFile(): fork failed (%s)\n",
141
ret = doWriteConfigFile(filename, cptr);
144
default: /* parent */
147
p = waitpid(pid, &status, 0);
148
} while (p == -1 && errno == EINTR);
151
signal(SIGCHLD, csig);
153
if (p != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0)
154
return 1; /* success */
158
#else /* HAS_SAVED_IDS_AND_SETEUID */
163
if (seteuid(ruid) == -1)
165
ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n",
166
ruid, strerror(errno));
169
ret = doWriteConfigFile(filename, cptr);
171
if (seteuid(euid) == -1)
173
ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n",
174
euid, strerror(errno));
178
#endif /* HAS_SAVED_IDS_AND_SETEUID */
183
return doWriteConfigFile(filename, cptr);
187
#endif /* !HAS_NO_UIDS */