~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/parser/write.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/write.c,v 1.17 2002/09/17 18:54:16 dawes Exp $ */
 
2
/* 
 
3
 * 
 
4
 * Copyright (c) 1997  Metro Link Incorporated
 
5
 * 
 
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:
 
12
 * 
 
13
 * The above copyright notice and this permission notice shall be included in
 
14
 * all copies or substantial portions of the Software.
 
15
 * 
 
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
 
22
 * SOFTWARE.
 
23
 * 
 
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.
 
27
 * 
 
28
 */
 
29
 
 
30
/* View/edit this file with tab stops set to 4 */
 
31
 
 
32
#include "xf86Parser.h"
 
33
#include "xf86tokens.h"
 
34
#include "Configint.h"
 
35
 
 
36
#include <unistd.h>
 
37
#include <sys/types.h>
 
38
#include <sys/wait.h>
 
39
#include <signal.h>
 
40
#include <errno.h>
 
41
 
 
42
#if ((defined(sun) && !defined(SVR4)) || defined(macII)) && !defined(__GLIBC__)
 
43
#ifndef strerror
 
44
extern char *sys_errlist[];
 
45
extern int sys_nerr;
 
46
#define strerror(n) \
 
47
        (((n) >= 0 && (n) < sys_nerr) ? sys_errlist[n] : "unknown error")
 
48
#endif
 
49
#endif
 
50
 
 
51
#if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
 
52
#define HAS_SAVED_IDS_AND_SETEUID
 
53
#endif
 
54
#if defined(__UNIXOS2__) || defined(WIN32)
 
55
#define HAS_NO_UIDS
 
56
#endif
 
57
 
 
58
#ifdef HAS_NO_UIDS
 
59
#define doWriteConfigFile xf86writeConfigFile
 
60
#define Local /**/
 
61
#else
 
62
#define Local static
 
63
#endif
 
64
 
 
65
Local int
 
66
doWriteConfigFile (const char *filename, XF86ConfigPtr cptr)
 
67
{
 
68
        FILE *cf;
 
69
 
 
70
        if ((cf = fopen (filename, "w")) == NULL)
 
71
        {
 
72
                return 0;
 
73
        }
 
74
 
 
75
        if (cptr->conf_comment)
 
76
                fprintf (cf, "%s\n", cptr->conf_comment);
 
77
 
 
78
        xf86printLayoutSection (cf, cptr->conf_layout_lst);
 
79
 
 
80
        fprintf (cf, "Section \"Files\"\n");
 
81
        xf86printFileSection (cf, cptr->conf_files);
 
82
        fprintf (cf, "EndSection\n\n");
 
83
 
 
84
        fprintf (cf, "Section \"Module\"\n");
 
85
        xf86printModuleSection (cf, cptr->conf_modules);
 
86
        fprintf (cf, "EndSection\n\n");
 
87
 
 
88
        xf86printVendorSection (cf, cptr->conf_vendor_lst);
 
89
 
 
90
        xf86printServerFlagsSection (cf, cptr->conf_flags);
 
91
 
 
92
        xf86printInputSection (cf, cptr->conf_input_lst);
 
93
 
 
94
        xf86printVideoAdaptorSection (cf, cptr->conf_videoadaptor_lst);
 
95
 
 
96
        xf86printModesSection (cf, cptr->conf_modes_lst);
 
97
 
 
98
        xf86printMonitorSection (cf, cptr->conf_monitor_lst);
 
99
 
 
100
        xf86printDeviceSection (cf, cptr->conf_device_lst);
 
101
 
 
102
        xf86printScreenSection (cf, cptr->conf_screen_lst);
 
103
 
 
104
        xf86printDRISection (cf, cptr->conf_dri);
 
105
 
 
106
        fclose(cf);
 
107
        return 1;
 
108
}
 
109
 
 
110
#ifndef HAS_NO_UIDS
 
111
 
 
112
int
 
113
xf86writeConfigFile (const char *filename, XF86ConfigPtr cptr)
 
114
{
 
115
        int ret;
 
116
 
 
117
#if !defined(HAS_SAVED_IDS_AND_SETEUID)
 
118
        int pid, p;
 
119
        int status;
 
120
        void (*csig)(int);
 
121
#else
 
122
        int ruid, euid;
 
123
#endif
 
124
 
 
125
        if (getuid() != geteuid())
 
126
        {
 
127
 
 
128
#if !defined(HAS_SAVED_IDS_AND_SETEUID)
 
129
                /* Need to fork to change ruid without loosing euid */
 
130
#ifdef SIGCHLD
 
131
                csig = signal(SIGCHLD, SIG_DFL);
 
132
#endif
 
133
                switch ((pid = fork()))
 
134
                {
 
135
                case -1:
 
136
                        ErrorF("xf86writeConfigFile(): fork failed (%s)\n",
 
137
                                        strerror(errno));
 
138
                        return 0;
 
139
                case 0: /* child */
 
140
                        setuid(getuid());
 
141
                        ret = doWriteConfigFile(filename, cptr);
 
142
                        exit(ret);
 
143
                        break;
 
144
                default: /* parent */
 
145
                        do
 
146
                        {
 
147
                                p = waitpid(pid, &status, 0);
 
148
                        } while (p == -1 && errno == EINTR);
 
149
                }
 
150
#ifdef SIGCHLD
 
151
                signal(SIGCHLD, csig);
 
152
#endif
 
153
                if (p != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0)
 
154
                        return 1;       /* success */
 
155
                else
 
156
                        return 0;
 
157
 
 
158
#else /* HAS_SAVED_IDS_AND_SETEUID */
 
159
 
 
160
                ruid = getuid();
 
161
                euid = geteuid();
 
162
 
 
163
                if (seteuid(ruid) == -1)
 
164
                {
 
165
                        ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n",
 
166
                                        ruid, strerror(errno));
 
167
                        return 0;
 
168
                }
 
169
                ret = doWriteConfigFile(filename, cptr);
 
170
 
 
171
                if (seteuid(euid) == -1)
 
172
                {
 
173
                        ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n",
 
174
                                        euid, strerror(errno));
 
175
                }
 
176
                return ret;
 
177
 
 
178
#endif /* HAS_SAVED_IDS_AND_SETEUID */
 
179
 
 
180
        }
 
181
        else
 
182
        {
 
183
                return doWriteConfigFile(filename, cptr);
 
184
        }
 
185
}
 
186
 
 
187
#endif /* !HAS_NO_UIDS */