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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/parser/Module.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/Module.c,v 1.11 2003/01/04 20:20:23 paulo 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
extern LexRec val;
 
37
 
 
38
static xf86ConfigSymTabRec SubModuleTab[] =
 
39
{
 
40
        {ENDSUBSECTION, "endsubsection"},
 
41
        {OPTION, "option"},
 
42
        {-1, ""},
 
43
};
 
44
 
 
45
static xf86ConfigSymTabRec ModuleTab[] =
 
46
{
 
47
        {ENDSECTION, "endsection"},
 
48
        {LOAD, "load"},
 
49
        {LOAD_DRIVER, "loaddriver"},
 
50
        {SUBSECTION, "subsection"},
 
51
        {-1, ""},
 
52
};
 
53
 
 
54
#define CLEANUP xf86freeModules
 
55
 
 
56
XF86LoadPtr
 
57
xf86parseModuleSubSection (XF86LoadPtr head, char *name)
 
58
{
 
59
        int token;
 
60
        parsePrologue (XF86LoadPtr, XF86LoadRec)
 
61
 
 
62
        ptr->load_name = name;
 
63
        ptr->load_type = XF86_LOAD_MODULE;
 
64
        ptr->load_opt  = NULL;
 
65
        ptr->list.next = NULL;
 
66
 
 
67
        while ((token = xf86getToken (SubModuleTab)) != ENDSUBSECTION)
 
68
        {
 
69
                switch (token)
 
70
                {
 
71
                case COMMENT:
 
72
                        ptr->load_comment = xf86addComment(ptr->load_comment, val.str);
 
73
                        break;
 
74
                case OPTION:
 
75
                        ptr->load_opt = xf86parseOption(ptr->load_opt);
 
76
                        break;
 
77
                case EOF_TOKEN:
 
78
                        xf86parseError (UNEXPECTED_EOF_MSG, NULL);
 
79
                        xf86conffree(ptr);
 
80
                        return NULL;
 
81
                default:
 
82
                        xf86parseError (INVALID_KEYWORD_MSG, xf86tokenString ());
 
83
                        xf86conffree(ptr);
 
84
                        return NULL;
 
85
                        break;
 
86
                }
 
87
 
 
88
        }
 
89
 
 
90
        return ((XF86LoadPtr) xf86addListItem ((glp) head, (glp) ptr));
 
91
}
 
92
 
 
93
XF86ConfModulePtr
 
94
xf86parseModuleSection (void)
 
95
{
 
96
        int token;
 
97
        parsePrologue (XF86ConfModulePtr, XF86ConfModuleRec)
 
98
 
 
99
        while ((token = xf86getToken (ModuleTab)) != ENDSECTION)
 
100
        {
 
101
                switch (token)
 
102
                {
 
103
                case COMMENT:
 
104
                        ptr->mod_comment = xf86addComment(ptr->mod_comment, val.str);
 
105
                        break;
 
106
                case LOAD:
 
107
                        if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
 
108
                                Error (QUOTE_MSG, "Load");
 
109
                        ptr->mod_load_lst =
 
110
                                xf86addNewLoadDirective (ptr->mod_load_lst, val.str,
 
111
                                                                         XF86_LOAD_MODULE, NULL);
 
112
                        break;
 
113
                case LOAD_DRIVER:
 
114
                        if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
 
115
                                Error (QUOTE_MSG, "LoadDriver");
 
116
                        ptr->mod_load_lst =
 
117
                                xf86addNewLoadDirective (ptr->mod_load_lst, val.str,
 
118
                                                                         XF86_LOAD_DRIVER, NULL);
 
119
                        break;
 
120
                case SUBSECTION:
 
121
                        if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
 
122
                                                Error (QUOTE_MSG, "SubSection");
 
123
                        ptr->mod_load_lst =
 
124
                                xf86parseModuleSubSection (ptr->mod_load_lst, val.str);
 
125
                        break;
 
126
                case EOF_TOKEN:
 
127
                        Error (UNEXPECTED_EOF_MSG, NULL);
 
128
                        break;
 
129
                default:
 
130
                        Error (INVALID_KEYWORD_MSG, xf86tokenString ());
 
131
                        break;
 
132
                }
 
133
        }
 
134
 
 
135
#ifdef DEBUG
 
136
        printf ("Module section parsed\n");
 
137
#endif
 
138
 
 
139
        return ptr;
 
140
}
 
141
 
 
142
#undef CLEANUP
 
143
 
 
144
void
 
145
xf86printModuleSection (FILE * cf, XF86ConfModulePtr ptr)
 
146
{
 
147
        XF86LoadPtr lptr;
 
148
 
 
149
        if (ptr == NULL)
 
150
                return;
 
151
 
 
152
        if (ptr->mod_comment)
 
153
                fprintf(cf, "%s", ptr->mod_comment);
 
154
        for (lptr = ptr->mod_load_lst; lptr; lptr = lptr->list.next)
 
155
        {
 
156
                switch (lptr->load_type)
 
157
                {
 
158
                case XF86_LOAD_MODULE:
 
159
                        if( lptr->load_opt == NULL ) {
 
160
                                fprintf (cf, "\tLoad  \"%s\"", lptr->load_name);
 
161
                                if (lptr->load_comment)
 
162
                                        fprintf(cf, "%s", lptr->load_comment);
 
163
                                else
 
164
                                        fputc('\n', cf);
 
165
                        }
 
166
                        else
 
167
                        {
 
168
                                fprintf (cf, "\tSubSection \"%s\"\n", lptr->load_name);
 
169
                                if (lptr->load_comment)
 
170
                                        fprintf(cf, "%s", lptr->load_comment);
 
171
                                xf86printOptionList(cf, lptr->load_opt, 2);
 
172
                                fprintf (cf, "\tEndSubSection\n");
 
173
                        }
 
174
                        break;
 
175
                case XF86_LOAD_DRIVER:
 
176
                        fprintf (cf, "\tLoadDriver  \"%s\"", lptr->load_name);
 
177
                                if (lptr->load_comment)
 
178
                                        fprintf(cf, "%s", lptr->load_comment);
 
179
                                else
 
180
                                        fputc('\n', cf);
 
181
                        break;
 
182
#if 0
 
183
                default:
 
184
                        fprintf (cf, "#\tUnknown type  \"%s\"\n", lptr->load_name);
 
185
                        break;
 
186
#endif
 
187
                }
 
188
        }
 
189
}
 
190
 
 
191
XF86LoadPtr
 
192
xf86addNewLoadDirective (XF86LoadPtr head, char *name, int type, XF86OptionPtr opts)
 
193
{
 
194
        XF86LoadPtr new;
 
195
        int token;
 
196
 
 
197
        new = xf86confcalloc (1, sizeof (XF86LoadRec));
 
198
        new->load_name = name;
 
199
        new->load_type = type;
 
200
        new->load_opt  = opts;
 
201
        new->list.next = NULL;
 
202
 
 
203
        if ((token = xf86getToken(NULL)) == COMMENT)
 
204
                new->load_comment = xf86addComment(new->load_comment, val.str);
 
205
        else
 
206
                xf86unGetToken(token);
 
207
 
 
208
        return ((XF86LoadPtr) xf86addListItem ((glp) head, (glp) new));
 
209
}
 
210
 
 
211
void
 
212
xf86freeModules (XF86ConfModulePtr ptr)
 
213
{
 
214
        XF86LoadPtr lptr;
 
215
        XF86LoadPtr prev;
 
216
 
 
217
        if (ptr == NULL)
 
218
                return;
 
219
        lptr = ptr->mod_load_lst;
 
220
        while (lptr)
 
221
        {
 
222
                TestFree (lptr->load_name);
 
223
                TestFree (lptr->load_comment);
 
224
                prev = lptr;
 
225
                lptr = lptr->list.next;
 
226
                xf86conffree (prev);
 
227
        }
 
228
        TestFree (ptr->mod_comment);
 
229
        xf86conffree (ptr);
 
230
}