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

« back to all changes in this revision

Viewing changes to unix/xc/lib/Xi/XExtToWire.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: XExtToWire.c,v 1.4 2001/02/09 02:03:50 xorgcvs Exp $ */
 
2
 
 
3
/************************************************************
 
4
 
 
5
Copyright 1989, 1998  The Open Group
 
6
 
 
7
Permission to use, copy, modify, distribute, and sell this software and its
 
8
documentation for any purpose is hereby granted without fee, provided that
 
9
the above copyright notice appear in all copies and that both that
 
10
copyright notice and this permission notice appear in supporting
 
11
documentation.
 
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 THE
 
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
Except as contained in this notice, the name of The Open Group shall not be
 
24
used in advertising or otherwise to promote the sale, use or other dealings
 
25
in this Software without prior written authorization from The Open Group.
 
26
 
 
27
Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
 
28
 
 
29
                        All Rights Reserved
 
30
 
 
31
Permission to use, copy, modify, and distribute this software and its
 
32
documentation for any purpose and without fee is hereby granted,
 
33
provided that the above copyright notice appear in all copies and that
 
34
both that copyright notice and this permission notice appear in
 
35
supporting documentation, and that the name of Hewlett-Packard not be
 
36
used in advertising or publicity pertaining to distribution of the
 
37
software without specific, written prior permission.
 
38
 
 
39
HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
40
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
41
HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
42
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
43
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
44
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
45
SOFTWARE.
 
46
 
 
47
********************************************************/
 
48
/* $XFree86: xc/lib/Xi/XExtToWire.c,v 3.6 2002/10/16 12:56:28 tsi Exp $ */
 
49
 
 
50
/****************************************************************
 
51
 *
 
52
 *      XExtToWire.c - reformat an XEvent into a wire event.
 
53
 */
 
54
 
 
55
#define NEED_EVENTS
 
56
#define NEED_REPLIES
 
57
 
 
58
#include <X11/extensions/XIproto.h>
 
59
#include <X11/Xlibint.h>
 
60
#include <X11/extensions/XInput.h>
 
61
#include <X11/extensions/extutil.h>
 
62
#include "XIint.h"
 
63
 
 
64
Status
 
65
_XiEventToWire(dpy, re, event, count)
 
66
    register Display *dpy;      /* pointer to display structure */
 
67
    register XEvent *re;        /* pointer to client event */
 
68
    register xEvent **event;    /* wire protocol event */
 
69
    register int *count;
 
70
    {
 
71
    XExtDisplayInfo *info = XInput_find_display (dpy);
 
72
    int i;
 
73
 
 
74
    switch ((re->type & 0x7f) - info->codes->first_event) 
 
75
        {
 
76
        case XI_DeviceKeyPress:
 
77
        case XI_DeviceKeyRelease:
 
78
            {
 
79
            register XDeviceKeyEvent *ev = (XDeviceKeyEvent*) re;
 
80
            register deviceKeyButtonPointer *kev;
 
81
            register deviceValuator *vev;
 
82
 
 
83
            *count = 2;
 
84
            kev = (deviceKeyButtonPointer *) Xmalloc (*count * sizeof (xEvent));
 
85
            if (!kev)
 
86
                return(_XUnknownNativeEvent(dpy, re, *event));
 
87
            *event = (xEvent *) kev;
 
88
 
 
89
            kev->type           = ev->type;
 
90
            kev->root           = ev->root;
 
91
            kev->event          = ev->window;
 
92
            kev->child          = ev->subwindow;
 
93
            kev->time           = ev->time;
 
94
            kev->event_x        = ev->x ;
 
95
            kev->event_y        = ev->y ;
 
96
            kev->root_x         = ev->x_root;
 
97
            kev->root_y         = ev->y_root;
 
98
            kev->state          = ev->state;
 
99
            kev->same_screen    = ev->same_screen;
 
100
            kev->detail         = ev->keycode;
 
101
            kev->deviceid       = ev->deviceid | MORE_EVENTS;
 
102
 
 
103
            vev = (deviceValuator *) ++kev;
 
104
            vev->type = info->codes->first_event + XI_DeviceValuator;
 
105
            vev->deviceid = ev->deviceid;
 
106
            vev->device_state = ev->device_state;
 
107
            vev->first_valuator = ev->first_axis;
 
108
            vev->num_valuators = ev->axes_count;
 
109
            i = vev->num_valuators;
 
110
            if (i > 6) i = 6;
 
111
            switch (i)
 
112
                {
 
113
                case 6: vev->valuator5 = ev->axis_data[5];
 
114
                case 5: vev->valuator4 = ev->axis_data[4];
 
115
                case 4: vev->valuator3 = ev->axis_data[3];
 
116
                case 3: vev->valuator2 = ev->axis_data[2];
 
117
                case 2: vev->valuator1 = ev->axis_data[1];
 
118
                case 1: vev->valuator0 = ev->axis_data[0];
 
119
                }
 
120
            break;
 
121
            }
 
122
        case XI_ProximityIn:
 
123
        case XI_ProximityOut:
 
124
            {
 
125
            register XProximityNotifyEvent *ev =  
 
126
                (XProximityNotifyEvent *) re;
 
127
            register deviceKeyButtonPointer *pev;
 
128
            register deviceValuator *vev;
 
129
 
 
130
            *count = 2;
 
131
            pev = (deviceKeyButtonPointer *) Xmalloc (*count * sizeof (xEvent));
 
132
            if (!pev)
 
133
                return(_XUnknownNativeEvent(dpy, re, *event));
 
134
            *event = (xEvent *) pev;
 
135
 
 
136
            pev->type           = ev->type;
 
137
            pev->root           = ev->root;
 
138
            pev->event          = ev->window;
 
139
            pev->child          = ev->subwindow;
 
140
            pev->time           = ev->time;
 
141
            pev->event_x        = ev->x ;
 
142
            pev->event_y        = ev->y ;
 
143
            pev->root_x         = ev->x_root;
 
144
            pev->root_y         = ev->y_root;
 
145
            pev->state          = ev->state;
 
146
            pev->same_screen    = ev->same_screen;
 
147
            pev->deviceid       = ev->deviceid | MORE_EVENTS;
 
148
 
 
149
            vev = (deviceValuator *) ++pev;
 
150
            vev->type = info->codes->first_event + XI_DeviceValuator;
 
151
            vev->deviceid = ev->deviceid;
 
152
            vev->device_state = ev->device_state;
 
153
            vev->first_valuator = ev->first_axis;
 
154
            vev->num_valuators = ev->axes_count;
 
155
 
 
156
            i = vev->num_valuators;
 
157
            if (i > 6) i = 6;
 
158
            switch (i)
 
159
                {
 
160
                case 6: vev->valuator5 = ev->axis_data[5];
 
161
                case 5: vev->valuator4 = ev->axis_data[4];
 
162
                case 4: vev->valuator3 = ev->axis_data[3];
 
163
                case 3: vev->valuator2 = ev->axis_data[2];
 
164
                case 2: vev->valuator1 = ev->axis_data[1];
 
165
                case 1: vev->valuator0 = ev->axis_data[0];
 
166
                }
 
167
            break;
 
168
            }
 
169
        case XI_DeviceButtonPress:
 
170
        case XI_DeviceButtonRelease:
 
171
            {
 
172
            register XDeviceButtonEvent *ev =  
 
173
                (XDeviceButtonEvent *) re;
 
174
            register deviceKeyButtonPointer *bev;
 
175
            register deviceValuator *vev;
 
176
 
 
177
            *count = 2;
 
178
            bev = (deviceKeyButtonPointer *) Xmalloc (*count * sizeof (xEvent));
 
179
            if (!bev)
 
180
                return(_XUnknownNativeEvent(dpy, re, *event));
 
181
            *event = (xEvent *) bev;
 
182
 
 
183
            bev->type           = ev->type;
 
184
            bev->root           = ev->root;
 
185
            bev->event          = ev->window;
 
186
            bev->child          = ev->subwindow;
 
187
            bev->time           = ev->time;
 
188
            bev->event_x        = ev->x ;
 
189
            bev->event_y        = ev->y ;
 
190
            bev->root_x         = ev->x_root;
 
191
            bev->root_y         = ev->y_root;
 
192
            bev->state          = ev->state;
 
193
            bev->same_screen    = ev->same_screen;
 
194
            bev->detail         = ev->button;
 
195
            bev->deviceid       = ev->deviceid | MORE_EVENTS;
 
196
 
 
197
            vev = (deviceValuator *) ++bev;
 
198
            vev->type = info->codes->first_event + XI_DeviceValuator;
 
199
            vev->deviceid = ev->deviceid;
 
200
            vev->device_state = ev->device_state;
 
201
            vev->first_valuator = ev->first_axis;
 
202
            vev->num_valuators = ev->axes_count;
 
203
 
 
204
            i = vev->num_valuators;
 
205
            if (i > 6) i = 6;
 
206
            switch (i)
 
207
                {
 
208
                case 6: vev->valuator5 = ev->axis_data[5];
 
209
                case 5: vev->valuator4 = ev->axis_data[4];
 
210
                case 4: vev->valuator3 = ev->axis_data[3];
 
211
                case 3: vev->valuator2 = ev->axis_data[2];
 
212
                case 2: vev->valuator1 = ev->axis_data[1];
 
213
                case 1: vev->valuator0 = ev->axis_data[0];
 
214
                }
 
215
            break;
 
216
            }
 
217
        case XI_DeviceMotionNotify:
 
218
            {
 
219
            register XDeviceMotionEvent *ev =   
 
220
                (XDeviceMotionEvent *)re;
 
221
            register deviceKeyButtonPointer *mev;
 
222
            register deviceValuator *vev;
 
223
 
 
224
            *count = 2;
 
225
            mev = (deviceKeyButtonPointer *) Xmalloc (*count * sizeof (xEvent));
 
226
            if (!mev)
 
227
                return(_XUnknownNativeEvent(dpy, re, *event));
 
228
            *event = (xEvent *) mev;
 
229
 
 
230
            mev->type           = ev->type;
 
231
            mev->root           = ev->root;
 
232
            mev->event          = ev->window;
 
233
            mev->child          = ev->subwindow;
 
234
            mev->time           = ev->time;
 
235
            mev->event_x        = ev->x ;
 
236
            mev->event_y        = ev->y ;
 
237
            mev->root_x         = ev->x_root;
 
238
            mev->root_y         = ev->y_root;
 
239
            mev->state          = ev->state;
 
240
            mev->same_screen    = ev->same_screen;
 
241
            mev->detail         = ev->is_hint;
 
242
            mev->deviceid       = ev->deviceid | MORE_EVENTS;
 
243
 
 
244
            vev = (deviceValuator *) ++mev;
 
245
            vev->type = info->codes->first_event + XI_DeviceValuator;
 
246
            vev->deviceid = ev->deviceid;
 
247
            vev->device_state = ev->device_state;
 
248
            vev->first_valuator = ev->first_axis;
 
249
            vev->num_valuators = ev->axes_count;
 
250
 
 
251
            i = vev->num_valuators;
 
252
            if (i > 6) i = 6;
 
253
            switch (i)
 
254
                {
 
255
                case 6: vev->valuator5 = ev->axis_data[5];
 
256
                case 5: vev->valuator4 = ev->axis_data[4];
 
257
                case 4: vev->valuator3 = ev->axis_data[3];
 
258
                case 3: vev->valuator2 = ev->axis_data[2];
 
259
                case 2: vev->valuator1 = ev->axis_data[1];
 
260
                case 1: vev->valuator0 = ev->axis_data[0];
 
261
                }
 
262
            break;
 
263
            }
 
264
        case XI_DeviceFocusIn:
 
265
        case XI_DeviceFocusOut:
 
266
            {
 
267
            register XDeviceFocusChangeEvent *ev = 
 
268
                (XDeviceFocusChangeEvent *) re;
 
269
            register deviceFocus *fev;
 
270
 
 
271
            *count = 1;
 
272
            fev = (deviceFocus *) Xmalloc (*count * sizeof (xEvent));
 
273
            if (!fev)
 
274
                return(_XUnknownNativeEvent(dpy, re, *event));
 
275
            *event = (xEvent *) fev;
 
276
 
 
277
            fev->type           = ev->type;
 
278
            fev->window         = ev->window;
 
279
            fev->mode           = ev->mode;
 
280
            fev->detail         = ev->detail;
 
281
            fev->time           = ev->time;
 
282
            fev->deviceid       = ev->deviceid;
 
283
            break;
 
284
            }
 
285
        case XI_DeviceMappingNotify:
 
286
            {
 
287
            register XDeviceMappingEvent *ev = (XDeviceMappingEvent *) re;
 
288
            register deviceMappingNotify *mev;
 
289
 
 
290
            *count = 1;
 
291
            mev = (deviceMappingNotify *) Xmalloc (*count * sizeof (xEvent));
 
292
            if (!mev)
 
293
                return(_XUnknownNativeEvent(dpy, re, *event));
 
294
            *event = (xEvent *) mev;
 
295
 
 
296
            mev->type           = ev->type;
 
297
            mev->firstKeyCode   = ev->first_keycode;
 
298
            mev->request        = ev->request;
 
299
            mev->count          = ev->count;
 
300
            mev->time           = ev->time;
 
301
            mev->deviceid       = ev->deviceid;
 
302
            break;
 
303
            }
 
304
        case XI_DeviceStateNotify:
 
305
            {
 
306
            register XDeviceStateNotifyEvent *ev = 
 
307
                (XDeviceStateNotifyEvent *) re;
 
308
            register deviceStateNotify *sev;
 
309
            register xEvent *tev;
 
310
            XInputClass *any = (XInputClass *) &ev->data[0];
 
311
            unsigned char *sav_id;
 
312
            *count = 1;
 
313
 
 
314
            for (i=0; i<ev->num_classes; i++)
 
315
                {
 
316
                if (any->class == KeyClass)
 
317
                    {
 
318
                    XKeyStatus *k = (XKeyStatus *) any;
 
319
                    if (k->num_keys > 32)
 
320
                        (*count)++;
 
321
                    }
 
322
                else if (any->class == ButtonClass)
 
323
                    {
 
324
                    XButtonStatus *b = (XButtonStatus *) any;
 
325
                    if (b->num_buttons > 32)
 
326
                        (*count)++;
 
327
                    }
 
328
                else if (any->class == ValuatorClass)
 
329
                    {
 
330
                    XValuatorStatus *v = (XValuatorStatus *) any;
 
331
                    if (v->num_valuators > 3)
 
332
                        (*count)++;
 
333
                    }
 
334
                any = (XInputClass *) ((char *) any + any->length);
 
335
                }
 
336
 
 
337
            sev = (deviceStateNotify *) Xmalloc (*count * sizeof (xEvent));
 
338
            if (!sev)
 
339
                return(_XUnknownNativeEvent(dpy, re, *event));
 
340
            *event = (xEvent *) sev;
 
341
            tev = (xEvent *) (sev+1);
 
342
 
 
343
            sev->type                   = ev->type;
 
344
            sev->deviceid               = ev->deviceid;
 
345
            sav_id                      = &(sev->deviceid);
 
346
            sev->time                   = ev->time;
 
347
            sev->classes_reported       = 0;
 
348
 
 
349
            any = (XInputClass *) &ev->data[0];
 
350
            for (i=0; i<ev->num_classes; i++)
 
351
                {
 
352
                if (any->class == KeyClass)
 
353
                    {
 
354
                    XKeyStatus *k = (XKeyStatus *) any;
 
355
                    register deviceKeyStateNotify *kev;
 
356
 
 
357
                    sev->classes_reported |= (1 << KeyClass);
 
358
                    sev->num_keys = k->num_keys;
 
359
                    memcpy ((char *) (sev->keys), (char *) (k->keys), 4);
 
360
                    if (k->num_keys > 32)
 
361
                        {
 
362
                        kev = (deviceKeyStateNotify *) tev++;
 
363
                        kev->type = info->codes->first_event + 
 
364
                                XI_DeviceKeystateNotify;
 
365
                        kev->deviceid = ev->deviceid;
 
366
                        *sav_id |= MORE_EVENTS;
 
367
                        sav_id = &(kev->deviceid);
 
368
                        memcpy ((char *) (kev->keys), (char *) (&k->keys[4]),
 
369
                                28);
 
370
                        }
 
371
                    }
 
372
                else if (any->class == ButtonClass)
 
373
                    {
 
374
                    XButtonStatus *b = (XButtonStatus *) any;
 
375
                    register deviceButtonStateNotify *bev;
 
376
 
 
377
                    sev->classes_reported |= (1 << ButtonClass);
 
378
                    sev->num_buttons = b->num_buttons;
 
379
                    memcpy ((char *) (sev->buttons), (char *) (b->buttons), 4);
 
380
                    if (b->num_buttons > 32)
 
381
                        {
 
382
                        bev = (deviceButtonStateNotify *) tev++;
 
383
                        bev->type = info->codes->first_event + 
 
384
                                XI_DeviceButtonstateNotify;
 
385
                        bev->deviceid = ev->deviceid;
 
386
                        *sav_id |= MORE_EVENTS;
 
387
                        sav_id = &(bev->deviceid);
 
388
                        memcpy ((char *)(bev->buttons), (char *)(&b->buttons[4]),
 
389
                                28);
 
390
                        }
 
391
                    }
 
392
                else if (any->class == ValuatorClass)
 
393
                    {
 
394
                    XValuatorStatus *val = (XValuatorStatus *) any;
 
395
                    register deviceValuator *vev;
 
396
 
 
397
                    sev->classes_reported |= (1 << ValuatorClass);
 
398
                    sev->num_valuators = val->num_valuators < 3 ?
 
399
                                         val->num_valuators : 3;
 
400
                    switch (sev->num_valuators)
 
401
                        {
 
402
                        case 3: sev->valuator2 = val->valuators[2];
 
403
                        case 2: sev->valuator1 = val->valuators[1];
 
404
                        case 1: sev->valuator0 = val->valuators[0];
 
405
                        }
 
406
                    if (val->num_valuators > 3)
 
407
                        {
 
408
                        vev = (deviceValuator *) tev++;
 
409
                        vev->type = info->codes->first_event + 
 
410
                                XI_DeviceValuator;
 
411
                        vev->deviceid = ev->deviceid;
 
412
                        vev->first_valuator = 3;
 
413
                        vev->num_valuators = val->num_valuators - 3;
 
414
                        *sav_id |= MORE_EVENTS;
 
415
                        sav_id = &(vev->deviceid);
 
416
                        i = val->num_valuators;
 
417
                        if (i > 6) i = 6;
 
418
                        switch (i)
 
419
                            {
 
420
                            case 6: vev->valuator2 = val->valuators[5];
 
421
                            case 5: vev->valuator1 = val->valuators[4];
 
422
                            case 4: vev->valuator0 = val->valuators[3];
 
423
                            }
 
424
                        }
 
425
                    }
 
426
                any = (XInputClass *) ((char *) any + any->length);
 
427
                }
 
428
            break;
 
429
            }
 
430
        case XI_ChangeDeviceNotify:
 
431
            {
 
432
            register XChangeDeviceNotifyEvent *ev = 
 
433
                (XChangeDeviceNotifyEvent *) re;
 
434
            register changeDeviceNotify *cev;
 
435
 
 
436
            *count = 1;
 
437
            cev = (changeDeviceNotify *) Xmalloc (*count * sizeof (xEvent));
 
438
            if (!cev)
 
439
                return(_XUnknownNativeEvent(dpy, re, *event));
 
440
            *event = (xEvent *) cev;
 
441
 
 
442
            cev->type           = ev->type;
 
443
            cev->request        = ev->request;
 
444
            cev->time           = ev->time;
 
445
            cev->deviceid       = ev->deviceid;
 
446
            break;
 
447
            }
 
448
        default:
 
449
            return(_XUnknownNativeEvent(dpy, re, *event));
 
450
        }
 
451
    return(1);
 
452
    }