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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/kdrive/itsy/kbd.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: kbd.c,v 1.1 1999/11/02 18:39:28 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/itsy/kbd.c,v 1.2 2000/02/23 20:29:59 dawes Exp $ */
 
25
 
 
26
#include "itsy.h"
 
27
#include "kkeymap.h"
 
28
#include <X11/keysym.h>
 
29
#include <linux/itsy_buttons.h>
 
30
 
 
31
#define ITSY_WIDTH  2
 
32
 
 
33
KeySym ItsyKeymap[] = {
 
34
/*      1     8 */       XK_Escape, NoSymbol,
 
35
/*      2     9 */       XK_1,  XK_exclam,
 
36
/*      3    10 */       XK_2,  XK_at,
 
37
/*      4    11 */       XK_3,  XK_numbersign,
 
38
/*      5    12 */       XK_4,  XK_dollar,
 
39
/*      6    13 */       XK_5,  XK_percent,
 
40
/*      7    14 */       XK_6,  XK_asciicircum,
 
41
/*      8    15 */       XK_7,  XK_ampersand,
 
42
/*      9    16 */       XK_8,  XK_asterisk,
 
43
/*     10    17 */       XK_9,  XK_parenleft,
 
44
/*     11    18 */       XK_0,  XK_parenright,
 
45
/*     12    19 */       XK_minus,      XK_underscore,
 
46
/*     13    20 */       XK_equal,      XK_plus,
 
47
/*     14    21 */       XK_BackSpace,  NoSymbol,
 
48
/*     15    22 */       XK_Tab,        NoSymbol,
 
49
/*     16    23 */       XK_Q,  NoSymbol,
 
50
/*     17    24 */       XK_W,  NoSymbol,
 
51
/*     18    25 */       XK_E,  NoSymbol,
 
52
/*     19    26 */       XK_R,  NoSymbol,
 
53
/*     20    27 */       XK_T,  NoSymbol,
 
54
/*     21    28 */       XK_Y,  NoSymbol,
 
55
/*     22    29 */       XK_U,  NoSymbol,
 
56
/*     23    30 */       XK_I,  NoSymbol,
 
57
/*     24    31 */       XK_O,  NoSymbol,
 
58
/*     25    32 */       XK_P,  NoSymbol,
 
59
/*     26    33 */       XK_bracketleft,        XK_braceleft,
 
60
/*     27    34 */       XK_bracketright,       XK_braceright,
 
61
/*     28    35 */       XK_Return,     NoSymbol,
 
62
/*     29    36 */       XK_Control_L,  NoSymbol,
 
63
/*     30    37 */       XK_A,  NoSymbol,
 
64
/*     31    38 */       XK_S,  NoSymbol,
 
65
/*     32    39 */       XK_D,  NoSymbol,
 
66
/*     33    40 */       XK_F,  NoSymbol,
 
67
/*     34    41 */       XK_G,  NoSymbol,
 
68
/*     35    42 */       XK_H,  NoSymbol,
 
69
/*     36    43 */       XK_J,  NoSymbol,
 
70
/*     37    44 */       XK_K,  NoSymbol,
 
71
/*     38    45 */       XK_L,  NoSymbol,
 
72
/*     39    46 */       XK_semicolon,  XK_colon,
 
73
/*     40    47 */       XK_apostrophe, XK_quotedbl,
 
74
/*     41    48 */       XK_grave,      XK_asciitilde,
 
75
/*     42    49 */       XK_Shift_L,    NoSymbol,
 
76
/*     43    50 */       XK_backslash,  XK_bar,
 
77
/*     44    51 */       XK_Z,  NoSymbol,
 
78
/*     45    52 */       XK_X,  NoSymbol,
 
79
/*     46    53 */       XK_C,  NoSymbol,
 
80
/*     47    54 */       XK_V,  NoSymbol,
 
81
/*     48    55 */       XK_B,  NoSymbol,
 
82
/*     49    56 */       XK_N,  NoSymbol,
 
83
/*     50    57 */       XK_M,  NoSymbol,
 
84
/*     51    58 */       XK_comma,      XK_less,
 
85
/*     52    59 */       XK_period,     XK_greater,
 
86
/*     53    60 */       XK_slash,      XK_question,
 
87
/*     54    61 */       XK_Shift_R,    NoSymbol,
 
88
/*     55    62 */       XK_KP_Multiply,        NoSymbol,
 
89
/*     56    63 */       XK_Alt_L,      XK_Meta_L,
 
90
/*     57    64 */       XK_space,      NoSymbol,
 
91
/*     58    65 */       XK_Caps_Lock,  NoSymbol,
 
92
/*     59    66 */       XK_F1, NoSymbol,
 
93
/*     60    67 */       XK_F2, NoSymbol,
 
94
/*     61    68 */       XK_F3, NoSymbol,
 
95
/*     62    69 */       XK_F4, NoSymbol,
 
96
/*     63    70 */       XK_F5, NoSymbol,
 
97
/*     64    71 */       XK_F6, NoSymbol,
 
98
/*     65    72 */       XK_F7, NoSymbol,
 
99
/*     66    73 */       XK_F8, NoSymbol,
 
100
/*     67    74 */       XK_F9, NoSymbol,
 
101
/*     68    75 */       XK_F10,        NoSymbol,
 
102
/*     69    76 */       XK_Break,      XK_Pause,
 
103
/*     70    77 */       XK_Scroll_Lock,        NoSymbol,
 
104
/*     71    78 */       XK_KP_Home,    XK_KP_7,
 
105
/*     72    79 */       XK_KP_Up,      XK_KP_8,
 
106
/*     73    80 */       XK_KP_Page_Up, XK_KP_9,
 
107
/*     74    81 */       XK_KP_Subtract,        NoSymbol,
 
108
/*     75    82 */       XK_KP_Left,    XK_KP_4,
 
109
/*     76    83 */       XK_KP_5,       NoSymbol,
 
110
/*     77    84 */       XK_KP_Right,   XK_KP_6,
 
111
/*     78    85 */       XK_KP_Add,     NoSymbol,
 
112
/*     79    86 */       XK_KP_End,     XK_KP_1,
 
113
/*     80    87 */       XK_KP_Down,    XK_KP_2,
 
114
/*     81    88 */       XK_KP_Page_Down,       XK_KP_3,
 
115
/*     82    89 */       XK_KP_Insert,  XK_KP_0,
 
116
/*     83    90 */       XK_KP_Delete,  XK_KP_Decimal,
 
117
/*     84    91 */     NoSymbol,        NoSymbol,
 
118
/*     85    92 */     NoSymbol,        NoSymbol,
 
119
/*     86    93 */     NoSymbol,        NoSymbol,
 
120
/*     87    94 */       XK_F11,        NoSymbol,
 
121
/*     88    95 */       XK_F12,        NoSymbol,
 
122
    
 
123
/* These are remapped from the extended set (using ExtendMap) */
 
124
    
 
125
/*     89    96 */       XK_Control_R,  NoSymbol,
 
126
/*     90    97 */       XK_KP_Enter,   NoSymbol,
 
127
/*     91    98 */       XK_KP_Divide,  NoSymbol,
 
128
/*     92    99 */       XK_Sys_Req,    XK_Print,
 
129
/*     93   100 */       XK_Alt_R,      XK_Meta_R,
 
130
/*     94   101 */       XK_Num_Lock,   NoSymbol,
 
131
/*     95   102 */       XK_Home,       NoSymbol,
 
132
/*     96   103 */       XK_Up,         NoSymbol,
 
133
/*     97   104 */       XK_Page_Up,    NoSymbol,
 
134
/*     98   105 */       XK_Left,       NoSymbol,
 
135
/*     99   106 */       XK_Right,      NoSymbol,
 
136
/*    100   107 */       XK_End,        NoSymbol,
 
137
/*    101   108 */       XK_Down,       NoSymbol,
 
138
/*    102   109 */       XK_Page_Down,  NoSymbol,
 
139
/*    103   110 */       XK_Insert,     NoSymbol,
 
140
/*    104   111 */       XK_Delete,     NoSymbol,
 
141
/*    105   112 */       XK_Super_L,    NoSymbol,
 
142
/*    106   113 */       XK_Super_R,    NoSymbol,
 
143
/*    107   114 */       XK_Menu,       NoSymbol,
 
144
 
 
145
/* Itsy hardware buttons */
 
146
#define ITSY_BUTTON_FIRST   108
 
147
#define ITSY_BUTTON_LAST    116
 
148
    
 
149
/*    108   115 */       XK_Next,       NoSymbol,   /* right button on side */
 
150
/*    109   116 */       XK_Prior,      NoSymbol,   /* left button on side */
 
151
/*    110   117 */       XK_Up,         NoSymbol,   /* joypad */
 
152
/*    111   118 */       XK_Down,       NoSymbol,
 
153
/*    112   119 */       XK_Left,       NoSymbol,
 
154
/*    113   120 */       XK_Right,      NoSymbol,
 
155
/*    114   121 */       NoSymbol,      NoSymbol,   /* left near speaker */
 
156
/*    115   122 */       NoSymbol,      NoSymbol,   /* right near speaker */
 
157
/*    116   123 */       NoSymbol,      NoSymbol,   /* tiny button */
 
158
};
 
159
 
 
160
static unsigned long    itsyButtonState;
 
161
 
 
162
void
 
163
ItsyKeyboardLoad (void)
 
164
{
 
165
    KeySym  *k;
 
166
 
 
167
    itsyButtonState = 0;
 
168
    kdMinScanCode = 1;
 
169
    kdKeymapWidth = ITSY_WIDTH;
 
170
    kdMaxScanCode = (sizeof (ItsyKeymap) / sizeof (ItsyKeymap[0])) / ITSY_WIDTH;
 
171
    memcpy (kdKeymap, ItsyKeymap, sizeof (ItsyKeymap));
 
172
}
 
173
 
 
174
int
 
175
ItsyKeyboardInit (void)
 
176
{
 
177
    int butPort;
 
178
 
 
179
    butPort = open ("/dev/buttons", 0);
 
180
    fprintf (stderr, "butPort %d\n", butPort);
 
181
    return butPort;
 
182
}
 
183
 
 
184
void
 
185
ItsyKeyboardFini (int fd)
 
186
{
 
187
    if (fd >= 0)
 
188
        close (fd);
 
189
}
 
190
 
 
191
void
 
192
ItsyKeyboardRead (int fd)
 
193
{
 
194
    itsy_buttons_event  event;
 
195
    int                 b;
 
196
    unsigned long       bit;
 
197
    unsigned long       change;
 
198
    unsigned long       buttons;
 
199
 
 
200
    if (read (fd, &event, sizeof (event)) == sizeof (event))
 
201
    {
 
202
        buttons = event.state;
 
203
        change = buttons ^ itsyButtonState;
 
204
        if (!change)
 
205
            return;
 
206
        for (b = ITSY_BUTTON_FIRST; b <= ITSY_BUTTON_LAST; b++)
 
207
        {
 
208
            bit = (1 << (b - ITSY_BUTTON_FIRST));
 
209
            if (change & bit)
 
210
                KdEnqueueKeyboardEvent (b, (buttons & bit) == 0);
 
211
        }
 
212
        itsyButtonState = buttons;
 
213
    }
 
214
}
 
215
 
 
216
void
 
217
ItsyKeyboardLeds (int leds)
 
218
{
 
219
}
 
220
 
 
221
void
 
222
ItsyKeyboardBell (int volume, int frequency, int duration)
 
223
{
 
224
}
 
225
 
 
226
KdKeyboardFuncs itsyKeyboardFuncs = {
 
227
    ItsyKeyboardLoad,
 
228
    ItsyKeyboardInit,
 
229
    ItsyKeyboardRead,
 
230
    ItsyKeyboardLeds,
 
231
    ItsyKeyboardBell,
 
232
    ItsyKeyboardFini,
 
233
    0,
 
234
};