~sbeattie/ubuntu/lucid/vnc4/lp556147

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/kdrive/kloadmap.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
/*
 
2
 * Id: kloadmap.c,v 1.1 1999/11/02 03:54:46 keithp Exp $
 
3
 *
 
4
 * Copyright � 1999 Keith Packard
 
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, and that the name of Keith Packard not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  Keith Packard makes no
 
13
 * representations about the suitability of this software for any purpose.  It
 
14
 * is provided "as is" without express or implied warranty.
 
15
 *
 
16
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
20
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
21
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
22
 * PERFORMANCE OF THIS SOFTWARE.
 
23
 */
 
24
/* $XFree86: xc/programs/Xserver/hw/kdrive/kloadmap.c,v 1.2 2000/02/23 20:29:54 dawes Exp $ */
 
25
 
 
26
#include "kdrive.h"
 
27
#include "kkeymap.h"
 
28
 
 
29
#ifdef WINDOWS
 
30
#define KM_BUF  1024
 
31
#define KM_EOF  -1
 
32
 
 
33
typedef struct _km_file {
 
34
    HANDLE  handle;
 
35
    char    buf[KM_BUF];
 
36
    char    *bufptr;
 
37
    DWORD   remain;
 
38
} km_file;
 
39
 
 
40
int
 
41
km_fill (km_file *kf)
 
42
{
 
43
    BOOL    r;
 
44
    
 
45
    NCD_DEBUG ((DEBUG_INIT, "km_fill"));
 
46
    r = ReadFile (kf->handle, kf->buf, KM_BUF,
 
47
                  &kf->remain, NULL);
 
48
    NCD_DEBUG ((DEBUG_INIT, "Got %d", kf->remain));
 
49
    if (!r || !kf->remain)
 
50
        return KM_EOF;
 
51
    kf->bufptr = kf->buf;
 
52
    --kf->remain;
 
53
    return *kf->bufptr++;
 
54
}
 
55
 
 
56
#define km_getchar(kf)  ((kf)->remain-- ? *kf->bufptr++ : km_fill (kf))
 
57
#else
 
58
#define km_getchar(kf)  getc(kf)
 
59
#endif
 
60
 
 
61
BOOL
 
62
km_word (km_file *kf, char *buf, int len)
 
63
{
 
64
    int     c;
 
65
 
 
66
    for (;;)
 
67
    {
 
68
        switch (c = km_getchar (kf)) {
 
69
        case KM_EOF:
 
70
            return FALSE;
 
71
        case ' ':
 
72
        case '\t':
 
73
        case '\n':
 
74
        case '\r':
 
75
            continue;
 
76
        }
 
77
        break;
 
78
    }
 
79
    len--;
 
80
    while (len--) 
 
81
    {
 
82
        *buf++ = c;
 
83
        switch (c = km_getchar (kf)) {
 
84
        case KM_EOF:
 
85
        case ' ':
 
86
        case '\t':
 
87
        case '\n':
 
88
        case '\r':
 
89
            *buf++ = '\0';
 
90
            return TRUE;
 
91
        }
 
92
    }
 
93
    return FALSE;
 
94
}
 
95
 
 
96
BOOL
 
97
km_int (km_file *kf, int *r)
 
98
{
 
99
    char    word[64];
 
100
 
 
101
    if (km_word (kf, word, sizeof (word)))
 
102
    {
 
103
        *r = strtol (word, NULL, 0);
 
104
        return TRUE;
 
105
    }
 
106
    return FALSE;
 
107
}
 
108
 
 
109
WCHAR *winKbdExtensions[] = {
 
110
    L".xku",
 
111
    L".xkb"
 
112
};
 
113
 
 
114
#define NUM_KBD_EXTENSIONS  (sizeof (winKbdExtensions) / sizeof (winKbdExtensions[0]))
 
115
 
 
116
BOOL
 
117
winLoadKeymap (void)
 
118
{
 
119
    WCHAR   file[32 + KL_NAMELENGTH];
 
120
    WCHAR   name[KL_NAMELENGTH];
 
121
    HKL     layout;
 
122
    km_file kf;
 
123
    int     width;
 
124
    BOOL    ret;
 
125
    KeySym  *m;
 
126
    int     scancode;
 
127
    int     w;
 
128
    int     e;
 
129
 
 
130
    layout = GetKeyboardLayout (0);
 
131
    /*
 
132
     * Pre-build 46 versions of ThinSTAR software return 0
 
133
     * for all layouts
 
134
     */
 
135
    if (!layout)
 
136
        return FALSE;
 
137
    NCD_DEBUG ((DEBUG_INIT, "Keyboard layout 0x%x", layout));
 
138
    for (e = 0; e < NUM_KBD_EXTENSIONS; e++)
 
139
    {
 
140
        wstrcpy (file, L"\\Storage Card\\");
 
141
        wsprintf (name, TEXT("%08x"), layout);
 
142
        wstrcat (file, name);
 
143
        wstrcat (file, winKbdExtensions[e]);
 
144
        NCD_DEBUG ((DEBUG_INIT, "Loading keymap from %S", file));
 
145
        kf.handle = CreateFile (file, 
 
146
                                GENERIC_READ,
 
147
                                FILE_SHARE_READ|FILE_SHARE_WRITE,
 
148
                                NULL,
 
149
                                OPEN_EXISTING,
 
150
                                FILE_ATTRIBUTE_NORMAL,
 
151
                                NULL);
 
152
        if (kf.handle != INVALID_HANDLE_VALUE)
 
153
            break;
 
154
    }
 
155
    if (kf.handle == INVALID_HANDLE_VALUE)
 
156
    {
 
157
        NCD_DEBUG ((DEBUG_INIT, "No such file"));
 
158
        return FALSE;
 
159
    }
 
160
    ret = FALSE;
 
161
    kf.remain = 0;
 
162
    /*
 
163
     * Keymap format:
 
164
     *
 
165
     *  flags (optional)
 
166
     *  width
 
167
     *  keycode -> keysym array  (num_keycodes * width)
 
168
     */
 
169
    if (!km_int (&kf, &width))
 
170
        goto bail1;
 
171
    if (width & KEYMAP_FLAGS)
 
172
    {
 
173
        CEKeymapFlags = (unsigned long) width;
 
174
        if (!km_int (&kf, &width))
 
175
            goto bail1;
 
176
    }
 
177
    else
 
178
        CEKeymapFlags = 0;
 
179
    if (width > MAX_WIDTH)
 
180
        goto bail1;
 
181
    NCD_DEBUG ((DEBUG_INIT, "Keymap width %d flags 0x%x", 
 
182
                width, CEKeymapFlags));
 
183
    m = CEKeymap;
 
184
    for (scancode = MIN_SCANCODE; scancode <= MAX_SCANCODE; scancode++)
 
185
    {
 
186
        for (w = 0; w < width; w++)
 
187
        {
 
188
            if (!km_int (&kf, m))
 
189
                break;
 
190
            m++;
 
191
        }
 
192
        if (w != width)
 
193
            break;
 
194
    }
 
195
    CEKeySyms.mapWidth = width;
 
196
    ret = TRUE;
 
197
bail1:
 
198
    CloseHandle (kf.handle);
 
199
    return ret;
 
200
}