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

« back to all changes in this revision

Viewing changes to unix/xc/programs/xdm/file.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
/* $Xorg: file.c,v 1.5 2001/02/09 02:05:40 xorgcvs Exp $ */
 
2
/*
 
3
 
 
4
Copyright 1988, 1998  The Open Group
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software and its
 
7
documentation for any purpose is hereby granted without fee, provided that
 
8
the above copyright notice appear in all copies and that both that
 
9
copyright notice and this permission notice appear in supporting
 
10
documentation.
 
11
 
 
12
The above copyright notice and this permission notice shall be included
 
13
in all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
16
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
18
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
19
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
20
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
21
OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
Except as contained in this notice, the name of The Open Group shall
 
24
not be used in advertising or otherwise to promote the sale, use or
 
25
other dealings in this Software without prior written authorization
 
26
from The Open Group.
 
27
 
 
28
*/
 
29
/* $XFree86: xc/programs/xdm/file.c,v 1.6 2001/12/14 20:01:21 dawes Exp $ */
 
30
 
 
31
/*
 
32
 * xdm - display manager daemon
 
33
 * Author:  Keith Packard, MIT X Consortium
 
34
 *
 
35
 * file.c
 
36
 */
 
37
 
 
38
# include       "dm.h"
 
39
# include       "dm_error.h"
 
40
 
 
41
# include       <ctype.h>
 
42
 
 
43
static int
 
44
DisplayTypeMatch (DisplayType d1, DisplayType d2)
 
45
{
 
46
        return d1.location == d2.location &&
 
47
               d1.lifetime == d2.lifetime &&
 
48
               d1.origin == d2.origin;
 
49
}
 
50
 
 
51
static void
 
52
freeFileArgs (char **args)
 
53
{
 
54
    char    **a;
 
55
 
 
56
    for (a = args; *a; a++)
 
57
        free (*a);
 
58
    free ((char *) args);
 
59
}
 
60
 
 
61
static char **
 
62
splitIntoWords (char *s)
 
63
{
 
64
    char    **args, **newargs;
 
65
    char    *wordStart;
 
66
    int     nargs;
 
67
 
 
68
    args = 0;
 
69
    nargs = 0;
 
70
    while (*s)
 
71
    {
 
72
        while (*s && isspace (*s))
 
73
            ++s;
 
74
        if (!*s || *s == '#')
 
75
            break;
 
76
        wordStart = s;
 
77
        while (*s && *s != '#' && !isspace (*s))
 
78
            ++s;
 
79
        if (!args)
 
80
        {
 
81
            args = (char **) malloc (2 * sizeof (char *));
 
82
            if (!args)
 
83
                return NULL;
 
84
        }
 
85
        else
 
86
        {
 
87
            newargs = (char **) realloc ((char *) args,
 
88
                                         (nargs+2)*sizeof (char *));
 
89
            if (!newargs)
 
90
            {
 
91
                freeFileArgs (args);
 
92
                return NULL;
 
93
            }
 
94
            args = newargs;
 
95
        }
 
96
        args[nargs] = malloc (s - wordStart + 1);
 
97
        if (!args[nargs])
 
98
        {
 
99
            freeFileArgs (args);
 
100
            return NULL;
 
101
        }
 
102
        strncpy (args[nargs], wordStart, s - wordStart);
 
103
        args[nargs][s-wordStart] = '\0';
 
104
        ++nargs;
 
105
        args[nargs] = NULL;
 
106
    }
 
107
    return args;
 
108
}
 
109
 
 
110
static char **
 
111
copyArgs (char **args)
 
112
{
 
113
    char    **a, **new, **n;
 
114
 
 
115
    for (a = args; *a; a++)
 
116
        /* SUPPRESS 530 */
 
117
        ;
 
118
    new = (char **) malloc ((a - args + 1) * sizeof (char *));
 
119
    if (!new)
 
120
        return NULL;
 
121
    n = new;
 
122
    a = args;
 
123
    /* SUPPRESS 560 */
 
124
    while ((*n++ = *a++))
 
125
        /* SUPPRESS 530 */
 
126
        ;
 
127
    return new;
 
128
}
 
129
 
 
130
static void
 
131
freeSomeArgs (char **args, int n)
 
132
{
 
133
    char    **a;
 
134
 
 
135
    a = args;
 
136
    while (n--)
 
137
        free (*a++);
 
138
    free ((char *) args);
 
139
}
 
140
 
 
141
void
 
142
ParseDisplay (char *source, DisplayType *acceptableTypes, int numAcceptable)
 
143
{
 
144
    char                **args, **argv, **a;
 
145
    char                *name, *class, *type;
 
146
    struct display      *d;
 
147
    int                 usedDefault;
 
148
    DisplayType         displayType;
 
149
 
 
150
    args = splitIntoWords (source);
 
151
    if (!args)
 
152
        return;
 
153
    if (!args[0])
 
154
    {
 
155
        LogError ("Missing display name in servers file\n");
 
156
        freeFileArgs (args);
 
157
        return;
 
158
    }
 
159
    name = args[0];
 
160
    if (!args[1])
 
161
    {
 
162
        LogError ("Missing display type for %s\n", args[0]);
 
163
        freeFileArgs (args);
 
164
        return;
 
165
    }
 
166
    displayType = parseDisplayType (args[1], &usedDefault);
 
167
    class = NULL;
 
168
    type = args[1];
 
169
    argv = args + 2;
 
170
    /*
 
171
     * extended syntax; if the second argument doesn't
 
172
     * exactly match a legal display type and the third
 
173
     * argument does, use the second argument as the
 
174
     * display class string
 
175
     */
 
176
    if (usedDefault && args[2])
 
177
    {
 
178
        displayType = parseDisplayType (args[2], &usedDefault);
 
179
        if (!usedDefault)
 
180
        {
 
181
            class = args[1];
 
182
            type = args[2];
 
183
            argv = args + 3;
 
184
        }
 
185
    }
 
186
    while (numAcceptable)
 
187
    {
 
188
        if (DisplayTypeMatch (*acceptableTypes, displayType))
 
189
            break;
 
190
        --numAcceptable;
 
191
        ++acceptableTypes;
 
192
    }
 
193
    if (!numAcceptable)
 
194
    {
 
195
        LogError ("Unacceptable display type %s for display %s\n",
 
196
                  type, name);
 
197
    }
 
198
    d = FindDisplayByName (name);
 
199
    if (d)
 
200
    {
 
201
        d->state = OldEntry;
 
202
        if (class && strcmp (d->class, class))
 
203
        {
 
204
            char    *newclass;
 
205
 
 
206
            newclass = malloc ((unsigned) (strlen (class) + 1));
 
207
            if (newclass)
 
208
            {
 
209
                free (d->class);
 
210
                strcpy (newclass, class);
 
211
                d->class = newclass;
 
212
            }
 
213
        }
 
214
        Debug ("Found existing display:  %s %s %s", d->name, d->class , type);
 
215
        freeFileArgs (d->argv);
 
216
    }
 
217
    else
 
218
    {
 
219
        d = NewDisplay (name, class);
 
220
        Debug ("Found new display:  %s %s %s", 
 
221
                d->name, d->class ? d->class : "", type);
 
222
    }
 
223
    d->displayType = displayType;
 
224
    d->argv = copyArgs (argv);
 
225
    for (a = d->argv; a && *a; a++)
 
226
        Debug (" %s", *a);
 
227
    Debug ("\n");
 
228
    freeSomeArgs (args, argv - args);
 
229
}
 
230
 
 
231
static struct displayMatch {
 
232
        char            *name;
 
233
        DisplayType     type;
 
234
} displayTypes[] = {
 
235
        { "local",              { Local, Permanent, FromFile } },
 
236
        { "foreign",            { Foreign, Permanent, FromFile } },
 
237
        { 0,                    { Local, Permanent, FromFile } },
 
238
};
 
239
 
 
240
DisplayType
 
241
parseDisplayType (char *string, int *usedDefault)
 
242
{
 
243
        struct displayMatch     *d;
 
244
 
 
245
        for (d = displayTypes; d->name; d++)
 
246
                if (!strcmp (d->name, string))
 
247
                {
 
248
                        *usedDefault = 0;
 
249
                        return d->type;
 
250
                }
 
251
        *usedDefault = 1;
 
252
        return d->type;
 
253
}