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

« back to all changes in this revision

Viewing changes to unix/xc/lib/X11/XKBleds.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: XKBleds.c,v 1.3 2000/08/17 19:45:03 cpqbld Exp $ */
 
2
/************************************************************
 
3
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
 
4
 
 
5
Permission to use, copy, modify, and distribute this
 
6
software and its documentation for any purpose and without
 
7
fee is hereby granted, provided that the above copyright
 
8
notice appear in all copies and that both that copyright
 
9
notice and this permission notice appear in supporting
 
10
documentation, and that the name of Silicon Graphics not be 
 
11
used in advertising or publicity pertaining to distribution 
 
12
of the software without specific prior written permission.
 
13
Silicon Graphics makes no representation about the suitability 
 
14
of this software for any purpose. It is provided "as is"
 
15
without any express or implied warranty.
 
16
 
 
17
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
 
18
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
 
19
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
 
20
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
 
21
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
 
22
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
 
23
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
 
24
THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
25
 
 
26
********************************************************/
 
27
/* $XFree86: xc/lib/X11/XKBleds.c,v 1.3 2001/02/21 15:18:03 tsi Exp $ */
 
28
 
 
29
#define NEED_REPLIES
 
30
#define NEED_EVENTS
 
31
#include "Xlibint.h"
 
32
#include <X11/extensions/XKBproto.h>
 
33
#include "XKBlibint.h"
 
34
 
 
35
Status
 
36
#if NeedFunctionPrototypes
 
37
XkbGetIndicatorState(Display *dpy,unsigned deviceSpec,unsigned *pStateRtrn)
 
38
#else
 
39
XkbGetIndicatorState(dpy,deviceSpec,pStateRtrn)
 
40
    Display *           dpy;
 
41
    unsigned int        deviceSpec;
 
42
    unsigned int *      pStateRtrn;
 
43
#endif
 
44
{
 
45
    register xkbGetIndicatorStateReq *req;
 
46
    xkbGetIndicatorStateReply   rep;
 
47
    XkbInfoPtr xkbi;
 
48
    Bool ok;
 
49
    
 
50
    if ((dpy->flags & XlibDisplayNoXkb) ||
 
51
        (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
 
52
        return BadAccess;
 
53
    LockDisplay(dpy);
 
54
    xkbi = dpy->xkb_info;
 
55
    GetReq(kbGetIndicatorState, req);
 
56
    req->reqType = xkbi->codes->major_opcode;
 
57
    req->xkbReqType = X_kbGetIndicatorState;
 
58
    req->deviceSpec = deviceSpec;
 
59
    ok=_XReply(dpy, (xReply *)&rep, 0, xFalse);
 
60
    if (ok && (pStateRtrn!=NULL))
 
61
        *pStateRtrn= rep.state;
 
62
    UnlockDisplay(dpy);
 
63
    SyncHandle();
 
64
    return (ok?Success:BadImplementation);
 
65
}
 
66
 
 
67
Status  
 
68
#if NeedFunctionPrototypes
 
69
_XkbReadGetIndicatorMapReply(   Display *                       dpy,
 
70
                                xkbGetIndicatorMapReply *       rep,
 
71
                                XkbDescPtr                      xkb,
 
72
                                int     *                       nread_rtrn)
 
73
#else
 
74
_XkbReadGetIndicatorMapReply(dpy,rep,xkb,nread_rtrn)
 
75
    Display *                   dpy;
 
76
    xkbGetIndicatorMapReply *   rep;
 
77
    XkbDescPtr                  xkb;
 
78
    int *                       nread_rtrn;
 
79
#endif
 
80
{
 
81
XkbIndicatorPtr         leds;
 
82
XkbReadBufferRec        buf;
 
83
 
 
84
    if ((!xkb->indicators)&&(XkbAllocIndicatorMaps(xkb)!=Success))
 
85
        return BadAlloc;
 
86
    leds= xkb->indicators;
 
87
 
 
88
    leds->phys_indicators = rep->realIndicators;
 
89
    if (rep->length>0) {
 
90
        register int left;
 
91
        if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
 
92
            return BadAlloc;
 
93
        if (nread_rtrn)
 
94
            *nread_rtrn= (int)rep->length*4;
 
95
        if (rep->which) {
 
96
            register int i,bit;
 
97
            left= (int)rep->which;
 
98
            for (i=0,bit=1;(i<XkbNumIndicators)&&(left);i++,bit<<=1) {
 
99
                if (left&bit) {
 
100
                    xkbIndicatorMapWireDesc *wire;
 
101
                    wire= (xkbIndicatorMapWireDesc *)
 
102
                          _XkbGetReadBufferPtr(&buf,
 
103
                                        SIZEOF(xkbIndicatorMapWireDesc));
 
104
                    if (wire==NULL) {
 
105
                        _XkbFreeReadBuffer(&buf);
 
106
                        return BadAlloc;
 
107
                    }
 
108
                    leds->maps[i].flags= wire->flags;
 
109
                    leds->maps[i].which_groups= wire->whichGroups;
 
110
                    leds->maps[i].groups= wire->groups;
 
111
                    leds->maps[i].which_mods= wire->whichMods;
 
112
                    leds->maps[i].mods.mask= wire->mods;
 
113
                    leds->maps[i].mods.real_mods= wire->realMods;
 
114
                    leds->maps[i].mods.vmods= wire->virtualMods;
 
115
                    leds->maps[i].ctrls= wire->ctrls;
 
116
                    left&= ~bit;
 
117
                }
 
118
            }
 
119
        }
 
120
        left= _XkbFreeReadBuffer(&buf);
 
121
    }
 
122
    return Success;
 
123
}
 
124
 
 
125
Bool
 
126
#if NeedFunctionPrototypes
 
127
XkbGetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb)
 
128
#else
 
129
XkbGetIndicatorMap(dpy,which,xkb)
 
130
    Display *           dpy;
 
131
    unsigned long       which;
 
132
    XkbDescPtr          xkb;
 
133
#endif
 
134
{
 
135
    register xkbGetIndicatorMapReq *    req;
 
136
    xkbGetIndicatorMapReply             rep;
 
137
    XkbInfoPtr                          xkbi;
 
138
    Status                              status;
 
139
 
 
140
    if ((dpy->flags & XlibDisplayNoXkb) ||
 
141
        (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
 
142
        return BadAccess;
 
143
    if ((!which)||(!xkb))
 
144
        return BadValue;
 
145
 
 
146
    LockDisplay(dpy);
 
147
    xkbi = dpy->xkb_info;
 
148
    if (!xkb->indicators) {
 
149
        xkb->indicators = _XkbTypedCalloc(1,XkbIndicatorRec);
 
150
        if (!xkb->indicators) {
 
151
            UnlockDisplay(dpy);
 
152
            SyncHandle();
 
153
            return BadAlloc;
 
154
        }
 
155
    }
 
156
    GetReq(kbGetIndicatorMap, req);
 
157
    req->reqType = xkbi->codes->major_opcode;
 
158
    req->xkbReqType = X_kbGetIndicatorMap;
 
159
    req->deviceSpec = xkb->device_spec;
 
160
    req->which = (CARD32)which;
 
161
    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 
162
        UnlockDisplay(dpy);
 
163
        SyncHandle();
 
164
        return BadValue;
 
165
    }
 
166
    status= _XkbReadGetIndicatorMapReply(dpy,&rep,xkb,NULL);
 
167
    UnlockDisplay(dpy);
 
168
    SyncHandle();
 
169
    return status;
 
170
}
 
171
 
 
172
Bool
 
173
#if NeedFunctionPrototypes
 
174
XkbSetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb)
 
175
#else
 
176
XkbSetIndicatorMap(dpy,which,xkb)
 
177
    Display *           dpy;
 
178
    unsigned long       which;
 
179
    XkbDescPtr          xkb;
 
180
#endif
 
181
{
 
182
    register xkbSetIndicatorMapReq      *req;
 
183
    register int i,bit;
 
184
    int nMaps;
 
185
    xkbIndicatorMapWireDesc *wire;
 
186
    XkbInfoPtr xkbi;
 
187
 
 
188
    if ((dpy->flags & XlibDisplayNoXkb) ||
 
189
        (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
 
190
        return False;
 
191
    if ((!xkb)||(!which)||(!xkb->indicators))
 
192
        return False;
 
193
    LockDisplay(dpy);
 
194
    xkbi = dpy->xkb_info;
 
195
    GetReq(kbSetIndicatorMap, req);
 
196
    req->reqType = xkbi->codes->major_opcode;
 
197
    req->xkbReqType = X_kbSetIndicatorMap;
 
198
    req->deviceSpec = xkb->device_spec;
 
199
    req->which = (CARD32)which;
 
200
    for (i=nMaps=0,bit=1;i<32;i++,bit<<=1) {
 
201
        if (which&bit)
 
202
            nMaps++;
 
203
    }
 
204
    req->length+= (nMaps*sizeof(XkbIndicatorMapRec))/4;
 
205
    BufAlloc(xkbIndicatorMapWireDesc *,wire,
 
206
                                       (nMaps*SIZEOF(xkbIndicatorMapWireDesc)));
 
207
    for (i=0,bit=1;i<32;i++,bit<<=1) {
 
208
        if (which&bit) {
 
209
            wire->flags= xkb->indicators->maps[i].flags;
 
210
            wire->whichGroups= xkb->indicators->maps[i].which_groups;
 
211
            wire->groups= xkb->indicators->maps[i].groups;
 
212
            wire->whichMods= xkb->indicators->maps[i].which_mods;
 
213
            wire->mods= xkb->indicators->maps[i].mods.real_mods;
 
214
            wire->virtualMods= xkb->indicators->maps[i].mods.vmods;
 
215
            wire->ctrls= xkb->indicators->maps[i].ctrls;
 
216
            wire++;
 
217
        }
 
218
    }
 
219
    UnlockDisplay(dpy);
 
220
    SyncHandle();
 
221
    return True;
 
222
}
 
223
 
 
224
Bool
 
225
#if NeedFunctionPrototypes
 
226
XkbGetNamedDeviceIndicator(     Display *               dpy,
 
227
                                unsigned                device,
 
228
                                unsigned                class,
 
229
                                unsigned                id,
 
230
                                Atom                    name,
 
231
                                int     *               pNdxRtrn,
 
232
                                Bool *                  pStateRtrn,
 
233
                                XkbIndicatorMapPtr      pMapRtrn,
 
234
                                Bool *                  pRealRtrn)
 
235
#else
 
236
XkbGetNamedDeviceIndicator(dpy,device,class,id,name,pNdxRtrn,pStateRtrn,
 
237
                                                        pMapRtrn,pRealRtrn)
 
238
    Display *           dpy;
 
239
    unsigned            device;
 
240
    unsigned            class;
 
241
    unsigned            id;
 
242
    Atom                name;
 
243
    int *               pNdxRtrn;
 
244
    Bool *              pStateRtrn;
 
245
    XkbIndicatorMapPtr  pMapRtrn;
 
246
    Bool *              pRealRtrn;
 
247
#endif
 
248
{
 
249
    register xkbGetNamedIndicatorReq *req;
 
250
    xkbGetNamedIndicatorReply   rep;
 
251
    XkbInfoPtr xkbi;
 
252
    
 
253
    if ((dpy->flags & XlibDisplayNoXkb) || (name==None) ||
 
254
        (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
 
255
        return False;
 
256
    LockDisplay(dpy);
 
257
    xkbi = dpy->xkb_info;
 
258
    GetReq(kbGetNamedIndicator, req);
 
259
    req->reqType = xkbi->codes->major_opcode;
 
260
    req->xkbReqType = X_kbGetNamedIndicator;
 
261
    req->deviceSpec = device;
 
262
    req->ledClass = class;
 
263
    req->ledID = id;
 
264
    req->indicator = (CARD32)name;
 
265
    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 
266
        UnlockDisplay(dpy);
 
267
        SyncHandle();
 
268
        return False;
 
269
    }
 
270
    if ((!rep.found)||(!rep.supported))
 
271
        return False;
 
272
    if (pNdxRtrn!=NULL)
 
273
        *pNdxRtrn= rep.ndx;
 
274
    if (pStateRtrn!=NULL)
 
275
        *pStateRtrn= rep.on;
 
276
    if (pMapRtrn!=NULL) {
 
277
        pMapRtrn->flags= rep.flags;
 
278
        pMapRtrn->which_groups= rep.whichGroups;
 
279
        pMapRtrn->groups= rep.groups;
 
280
        pMapRtrn->which_mods= rep.whichMods;
 
281
        pMapRtrn->mods.mask= rep.mods;
 
282
        pMapRtrn->mods.real_mods= rep.realMods;
 
283
        pMapRtrn->mods.vmods= rep.virtualMods;
 
284
        pMapRtrn->ctrls= rep.ctrls;
 
285
    }
 
286
    if (pRealRtrn!=NULL) 
 
287
        *pRealRtrn= rep.realIndicator;
 
288
    return True;
 
289
}
 
290
 
 
291
Bool
 
292
#if NeedFunctionPrototypes
 
293
XkbGetNamedIndicator(   Display *               dpy,
 
294
                        Atom                    name,
 
295
                        int     *               pNdxRtrn,
 
296
                        Bool *                  pStateRtrn,
 
297
                        XkbIndicatorMapPtr      pMapRtrn,
 
298
                        Bool *                  pRealRtrn)
 
299
#else
 
300
XkbGetNamedIndicator(dpy,name,pNdxRtrn,pStateRtrn,pMapRtrn,pRealRtrn)
 
301
    Display *           dpy;
 
302
    Atom                name;
 
303
    int *               pNdxRtrn;
 
304
    Bool *              pStateRtrn;
 
305
    XkbIndicatorMapPtr  pMapRtrn;
 
306
    Bool *              pRealRtrn;
 
307
#endif
 
308
{
 
309
    return XkbGetNamedDeviceIndicator(dpy,XkbUseCoreKbd,
 
310
                                          XkbDfltXIClass,XkbDfltXIId,
 
311
                                          name,pNdxRtrn,pStateRtrn,
 
312
                                          pMapRtrn,pRealRtrn);
 
313
}
 
314
 
 
315
Bool
 
316
#if NeedFunctionPrototypes
 
317
XkbSetNamedDeviceIndicator(     Display *               dpy,
 
318
                                unsigned                device,
 
319
                                unsigned                class,
 
320
                                unsigned                id,
 
321
                                Atom                    name,
 
322
                                Bool                    changeState,
 
323
                                Bool                    state,
 
324
                                Bool                    createNewMap,
 
325
                                XkbIndicatorMapPtr      pMap)
 
326
#else
 
327
XkbSetNamedDeviceIndicator(dpy,device,class,id,name,changeState,
 
328
                                                        state,createNewMap,pMap)
 
329
    Display *           dpy;
 
330
    unsigned            device;
 
331
    unsigned            class;
 
332
    unsigned            id;
 
333
    Atom                name;
 
334
    Bool                changeState;
 
335
    Bool                state;
 
336
    Bool                createNewMap;
 
337
    XkbIndicatorMapPtr  pMap;
 
338
#endif
 
339
{
 
340
    register xkbSetNamedIndicatorReq    *req;
 
341
    XkbInfoPtr xkbi;
 
342
 
 
343
    if ((dpy->flags & XlibDisplayNoXkb) || (name==None) ||
 
344
        (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
 
345
        return False;
 
346
    LockDisplay(dpy);
 
347
    xkbi = dpy->xkb_info;
 
348
    GetReq(kbSetNamedIndicator, req);
 
349
    req->reqType = xkbi->codes->major_opcode;
 
350
    req->xkbReqType = X_kbSetNamedIndicator;
 
351
    req->deviceSpec = device;
 
352
    req->ledClass = class;
 
353
    req->ledID = id;
 
354
    req->indicator= (CARD32)name;
 
355
    req->setState= changeState;
 
356
    if (req->setState)
 
357
         req->on= state;
 
358
    else req->on= False;
 
359
    if (pMap!=NULL) {
 
360
        req->setMap= True;
 
361
        req->createMap= createNewMap;
 
362
        req->flags= pMap->flags;
 
363
        req->whichGroups= pMap->which_groups;
 
364
        req->groups= pMap->groups;
 
365
        req->whichMods= pMap->which_mods;
 
366
        req->realMods= pMap->mods.real_mods;
 
367
        req->virtualMods= pMap->mods.vmods;
 
368
        req->ctrls= pMap->ctrls;
 
369
    }
 
370
    else {
 
371
        req->setMap=            False;
 
372
        req->createMap=         False;
 
373
        req->flags=             0;
 
374
        req->whichGroups=       0;
 
375
        req->groups=            0;
 
376
        req->whichMods=         0;
 
377
        req->realMods=          0;
 
378
        req->virtualMods=       0;
 
379
        req->ctrls=             0;
 
380
    }
 
381
    UnlockDisplay(dpy);
 
382
    SyncHandle();
 
383
    return True;
 
384
}
 
385
 
 
386
Bool
 
387
#if NeedFunctionPrototypes
 
388
XkbSetNamedIndicator(   Display *               dpy,
 
389
                        Atom                    name,
 
390
                        Bool                    changeState,
 
391
                        Bool                    state,
 
392
                        Bool                    createNewMap,
 
393
                        XkbIndicatorMapPtr      pMap)
 
394
#else
 
395
XkbSetNamedIndicator(dpy,name,changeState,state,createNewMap,pMap)
 
396
    Display *           dpy;
 
397
    Atom                name;
 
398
    Bool                changeState;
 
399
    Bool                state;
 
400
    Bool                createNewMap;
 
401
    XkbIndicatorMapPtr  pMap;
 
402
#endif
 
403
{
 
404
    return XkbSetNamedDeviceIndicator(dpy,XkbUseCoreKbd,
 
405
                                          XkbDfltXIClass,XkbDfltXIId,
 
406
                                          name,changeState,state,
 
407
                                          createNewMap,pMap);
 
408
}