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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/Xi/chgkbd.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: chgkbd.c,v 1.4 2001/02/09 02:04:33 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/programs/Xserver/Xi/chgkbd.c,v 3.6 2001/12/14 19:58:54 dawes Exp $ */
 
49
 
 
50
/***********************************************************************
 
51
 *
 
52
 * Extension function to change the keyboard device.
 
53
 *
 
54
 */
 
55
 
 
56
#define  NEED_EVENTS
 
57
#define  NEED_REPLIES
 
58
#include "X.h"                          /* for inputstr.h    */
 
59
#include "Xproto.h"                     /* Request macro     */
 
60
#include "inputstr.h"                   /* DeviceIntPtr      */
 
61
#include "XI.h"
 
62
#include "XIproto.h"
 
63
#include "XIstubs.h"
 
64
#include "globals.h"
 
65
#include "extnsionst.h"
 
66
#include "extinit.h"                    /* LookupDeviceIntRec */
 
67
 
 
68
#include "exevents.h"
 
69
#include "exglobals.h"
 
70
 
 
71
#include "chgkbd.h"
 
72
#include "chgptr.h"
 
73
 
 
74
/***********************************************************************
 
75
 *
 
76
 * This procedure changes the keyboard device.
 
77
 *
 
78
 */
 
79
 
 
80
int
 
81
SProcXChangeKeyboardDevice(client)
 
82
    register ClientPtr client;
 
83
    {
 
84
    register char n;
 
85
 
 
86
    REQUEST(xChangeKeyboardDeviceReq);
 
87
    swaps(&stuff->length, n);
 
88
    REQUEST_SIZE_MATCH(xChangeKeyboardDeviceReq);
 
89
    return(ProcXChangeKeyboardDevice(client));
 
90
    }
 
91
 
 
92
/***********************************************************************
 
93
 *
 
94
 * This procedure is invoked to swap the request bytes if the server and
 
95
 * client have a different byte order.
 
96
 *
 
97
 */
 
98
 
 
99
int
 
100
ProcXChangeKeyboardDevice (client)
 
101
    register ClientPtr client;
 
102
    {
 
103
    int                         i;
 
104
    DeviceIntPtr                xkbd = inputInfo.keyboard;
 
105
    DeviceIntPtr                dev;
 
106
    FocusClassPtr               xf = xkbd->focus;
 
107
    FocusClassPtr               df;
 
108
    KeyClassPtr                 k;
 
109
    xChangeKeyboardDeviceReply  rep;
 
110
    changeDeviceNotify          ev;
 
111
 
 
112
    REQUEST(xChangeKeyboardDeviceReq);
 
113
    REQUEST_SIZE_MATCH(xChangeKeyboardDeviceReq);
 
114
 
 
115
    rep.repType = X_Reply;
 
116
    rep.RepType = X_ChangeKeyboardDevice;
 
117
    rep.length = 0;
 
118
    rep.sequenceNumber = client->sequence;
 
119
 
 
120
    dev = LookupDeviceIntRec (stuff->deviceid);
 
121
    if (dev == NULL)
 
122
        {
 
123
        rep.status = -1;
 
124
        SendErrorToClient(client, IReqCode, X_ChangeKeyboardDevice, 0, 
 
125
                BadDevice);
 
126
        return Success;
 
127
        }
 
128
 
 
129
    k = dev->key;
 
130
    if (k == NULL)
 
131
        {
 
132
        rep.status = -1;
 
133
        SendErrorToClient(client, IReqCode, X_ChangeKeyboardDevice, 0, 
 
134
                BadMatch);
 
135
        return Success;
 
136
        }
 
137
 
 
138
    if (((dev->grab) && !SameClient(dev->grab, client)) ||
 
139
        ((xkbd->grab) && !SameClient(xkbd->grab, client)))
 
140
        rep.status = AlreadyGrabbed;
 
141
    else if ((dev->sync.frozen &&
 
142
             dev->sync.other && !SameClient(dev->sync.other, client)) ||
 
143
             (xkbd->sync.frozen &&
 
144
              xkbd->sync.other && !SameClient(xkbd->sync.other, client)))
 
145
        rep.status = GrabFrozen;
 
146
    else
 
147
        {
 
148
        if (ChangeKeyboardDevice (xkbd, dev) != Success)
 
149
            {
 
150
            SendErrorToClient(client, IReqCode, X_ChangeKeyboardDevice, 0, 
 
151
                BadDevice);
 
152
            return Success;
 
153
            }
 
154
        if (!dev->focus)
 
155
            InitFocusClassDeviceStruct (dev);
 
156
        if (!dev->kbdfeed)
 
157
           InitKbdFeedbackClassDeviceStruct(dev, (BellProcPtr)NoopDDA,
 
158
                                            (KbdCtrlProcPtr)NoopDDA);
 
159
        df = dev->focus;
 
160
        df->win = xf->win;
 
161
        df->revert = xf->revert;
 
162
        df->time = xf->time;
 
163
        df->traceGood = xf->traceGood;
 
164
        if (df->traceSize != xf->traceSize)
 
165
            {
 
166
            Must_have_memory = TRUE; /* XXX */
 
167
            df->trace = (WindowPtr *) xrealloc(df->trace, 
 
168
                xf->traceSize * sizeof(WindowPtr));
 
169
            Must_have_memory = FALSE; /* XXX */
 
170
            }
 
171
        df->traceSize = xf->traceSize;
 
172
        for (i=0; i<df->traceSize; i++)
 
173
            df->trace[i] = xf->trace[i];
 
174
        RegisterOtherDevice (xkbd);
 
175
        RegisterKeyboardDevice (dev);
 
176
 
 
177
        ev.type = ChangeDeviceNotify;
 
178
        ev.deviceid = stuff->deviceid;
 
179
        ev.time = currentTime.milliseconds;
 
180
        ev.request = NewKeyboard;
 
181
 
 
182
        SendEventToAllWindows (dev, ChangeDeviceNotifyMask, (xEvent *)&ev, 1);
 
183
        SendMappingNotify (MappingKeyboard, k->curKeySyms.minKeyCode, 
 
184
            k->curKeySyms.maxKeyCode - k->curKeySyms.minKeyCode + 1,client);
 
185
 
 
186
        rep.status = 0;
 
187
        }
 
188
 
 
189
    WriteReplyToClient (client, sizeof (xChangeKeyboardDeviceReply), 
 
190
        &rep);
 
191
    return Success;
 
192
    }
 
193
 
 
194
/***********************************************************************
 
195
 *
 
196
 * This procedure writes the reply for the XChangeKeyboardDevice 
 
197
 * function, if the client and server have a different byte ordering.
 
198
 *
 
199
 */
 
200
 
 
201
void
 
202
SRepXChangeKeyboardDevice (client, size, rep)
 
203
    ClientPtr   client;
 
204
    int         size;
 
205
    xChangeKeyboardDeviceReply  *rep;
 
206
    {
 
207
    register char n;
 
208
 
 
209
    swaps(&rep->sequenceNumber, n);
 
210
    swapl(&rep->length, n);
 
211
    WriteToClient(client, size, (char *)rep);
 
212
    }