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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/PEX5/dipex/objects/pexLut.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: pexLut.c,v 1.4 2001/02/09 02:04:14 xorgcvs Exp $ */
 
2
/*
 
3
 
 
4
Copyright 1989, 1990, 1991, 1998  The Open Group
 
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.
 
11
 
 
12
The above copyright notice and this permission notice shall be included
 
13
in all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
16
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
18
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
19
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
20
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
21
OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
Except as contained in this notice, the name of The Open Group shall
 
24
not be used in advertising or otherwise to promote the sale, use or
 
25
other dealings in this Software without prior written authorization
 
26
from The Open Group.
 
27
 
 
28
 
 
29
Copyright 1989, 1990, 1991 by Sun Microsystems, Inc.
 
30
 
 
31
                        All Rights Reserved
 
32
 
 
33
Permission to use, copy, modify, and distribute this software and its 
 
34
documentation for any purpose and without fee is hereby granted, 
 
35
provided that the above copyright notice appear in all copies and that
 
36
both that copyright notice and this permission notice appear in 
 
37
supporting documentation, and that the name of Sun Microsystems,
 
38
not be used in advertising or publicity pertaining to distribution
 
39
of the software without specific, written prior permission.  
 
40
 
 
41
SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
 
42
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
 
43
SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
 
44
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
45
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
46
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
47
SOFTWARE.
 
48
 
 
49
*/
 
50
/* $XFree86: xc/programs/Xserver/PEX5/dipex/objects/pexLut.c,v 3.9 2001/12/14 19:57:43 dawes Exp $ */
 
51
 
 
52
 
 
53
/*++
 
54
 *      PEXCreateLookupTable
 
55
 *      PEXCopyLookupTable
 
56
 *      PEXFreeLookupTable
 
57
 *      PEXGetTableInfo
 
58
 *      PEXGetPredefinedEntries
 
59
 *      PEXGetDefinedIndices
 
60
 *      PEXGetTableEntry
 
61
 *      PEXGetTableEntries
 
62
 *      PEXSetTableEntries
 
63
 *      PEXDeleteTableEntries
 
64
 --*/
 
65
 
 
66
#include "X.h"
 
67
#include "Xproto.h"
 
68
#include "pexError.h"
 
69
#include "PEXproto.h"
 
70
#include "dipex.h"
 
71
#include "pex_site.h"
 
72
#include "pexLookup.h"
 
73
#include "pexos.h"
 
74
 
 
75
 
 
76
#define VALID_TABLETYPE(type)   ((type > 0) && (type <= PEXMaxTableType))
 
77
 
 
78
 
 
79
#ifdef min
 
80
#undef min
 
81
#endif
 
82
 
 
83
#ifdef max
 
84
#undef max
 
85
#endif
 
86
 
 
87
 
 
88
 
 
89
/*++    PEXCreateLookupTable
 
90
 --*/
 
91
ErrorCode
 
92
PEXCreateLookupTable (cntxtPtr, strmPtr)
 
93
pexContext              *cntxtPtr;      /* context pointer      */
 
94
pexCreateLookupTableReq *strmPtr;       /* stream pointer       */
 
95
{
 
96
    ErrorCode freeLUT ();
 
97
    ErrorCode err = Success; 
 
98
    DrawablePtr pdraw = 0;
 
99
    diLUTHandle lutptr = 0;
 
100
 
 
101
    if (!VALID_TABLETYPE(strmPtr->tableType))
 
102
        PEX_ERR_EXIT(BadValue,strmPtr->tableType,cntxtPtr);
 
103
 
 
104
    if (!LegalNewID(strmPtr->lut, cntxtPtr->client))
 
105
        PEX_ERR_EXIT(BadIDChoice,strmPtr->lut,cntxtPtr);
 
106
 
 
107
    LU_DRAWABLE(strmPtr->drawableExample, pdraw);
 
108
 
 
109
    lutptr = (diLUTHandle) xalloc ((unsigned long)sizeof(ddLUTResource));
 
110
    if (!lutptr) PEX_ERR_EXIT (BadAlloc,0,cntxtPtr);
 
111
    lutptr->id = strmPtr->lut;
 
112
    lutptr->lutType = strmPtr->tableType;
 
113
    
 
114
    err = CreateLUT( pdraw, lutptr);
 
115
    if (err) {
 
116
        xfree((pointer)lutptr);
 
117
        PEX_ERR_EXIT(err,0,cntxtPtr);
 
118
    }
 
119
 
 
120
    ADDRESOURCE (strmPtr->lut, PEXLutType, lutptr);
 
121
 
 
122
    return( err );
 
123
 
 
124
} /* end-PEXCreateLookupTable() */
 
125
 
 
126
/*++    PEXCopyLookupTable
 
127
 --*/
 
128
ErrorCode
 
129
PEXCopyLookupTable (cntxtPtr, strmPtr)
 
130
pexContext              *cntxtPtr;      /* Context Pointer      */
 
131
pexCopyLookupTableReq   *strmPtr;       /* Stream Pointer       */
 
132
{
 
133
    diLUTHandle lsrc, ldest;
 
134
    ErrorCode err = Success;
 
135
 
 
136
    LU_TABLE(strmPtr->src, lsrc);
 
137
    LU_TABLE(strmPtr->dst, ldest);
 
138
 
 
139
    err = CopyLUT (lsrc, ldest);
 
140
    if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
 
141
 
 
142
    return (err);
 
143
 
 
144
} /* end-PEXCopyLookupTable() */
 
145
 
 
146
/*++    PEXFreeLookupTable
 
147
 --*/
 
148
ErrorCode
 
149
PEXFreeLookupTable (cntxtPtr, strmPtr)
 
150
pexContext              *cntxtPtr;      /* Context Pointer      */
 
151
pexFreeLookupTableReq   *strmPtr;       /* Stream Pointer       */
 
152
{
 
153
    ErrorCode err = Success;
 
154
    diLUTHandle l = 0;
 
155
 
 
156
    if ((strmPtr == NULL) || (strmPtr->id == 0)) {
 
157
        err = PEX_ERROR_CODE(PEXLookupTableError);
 
158
        PEX_ERR_EXIT(err,0,cntxtPtr);
 
159
    }
 
160
 
 
161
    LU_TABLE(strmPtr->id, l);
 
162
 
 
163
    FreeResource(strmPtr->id, RT_NONE);
 
164
 
 
165
    return( err );
 
166
 
 
167
} /* end-PEXFreeLookupTable() */
 
168
 
 
169
/*++    PEXGetTableInfoReq
 
170
 --*/
 
171
 
 
172
ErrorCode
 
173
PEXGetTableInfo( cntxtPtr, strmPtr )
 
174
pexContext              *cntxtPtr;
 
175
pexGetTableInfoReq      *strmPtr;
 
176
{
 
177
    ErrorCode err = Success;
 
178
    DrawablePtr pdraw;
 
179
    extern ddBufferPtr pPEXBuffer;
 
180
    pexGetTableInfoReply *reply = (pexGetTableInfoReply *)(pPEXBuffer->pHead);
 
181
 
 
182
    if (!VALID_TABLETYPE(strmPtr->tableType))
 
183
        PEX_ERR_EXIT(BadValue,strmPtr->tableType,cntxtPtr);
 
184
 
 
185
    LU_DRAWABLE(strmPtr->drawableExample, pdraw);
 
186
 
 
187
    SETUP_INQ(pexGetTableInfoReply);
 
188
 
 
189
    err = InquireLUTInfo(   pdraw, strmPtr->tableType,
 
190
                            (pexTableInfo *)&(reply->definableEntries));
 
191
    if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
 
192
 
 
193
    reply->length = 0;
 
194
    WritePEXReplyToClient(  cntxtPtr, strmPtr,
 
195
                            sizeof(pexGetTableInfoReply) + reply->length,
 
196
                            reply);
 
197
    return( err );
 
198
 
 
199
} /* end-PEXGetTableInfo() */
 
200
 
 
201
/*++    PEXGetPredefinedEntries
 
202
 --*/
 
203
 
 
204
ErrorCode
 
205
PEXGetPredefinedEntries( cntxtPtr, strmPtr )
 
206
pexContext                      *cntxtPtr;
 
207
pexGetPredefinedEntriesReq      *strmPtr;
 
208
{
 
209
    ErrorCode err = Success;
 
210
    extern ddBufferPtr pPEXBuffer;
 
211
    DrawablePtr pdraw = 0;
 
212
    ddULONG numEntries =  (ddULONG)(strmPtr->count);
 
213
 
 
214
    if (!VALID_TABLETYPE(strmPtr->tableType))
 
215
        PEX_ERR_EXIT(BadValue,strmPtr->tableType,cntxtPtr);
 
216
 
 
217
    LU_DRAWABLE(strmPtr->drawableExample, pdraw);
 
218
 
 
219
    SETUP_INQ(pexGetPredefinedEntriesReply);
 
220
 
 
221
    err = InquireLUTPredEntries(    pdraw, strmPtr->tableType,
 
222
                                    strmPtr->start, strmPtr->count,
 
223
                                    &numEntries, pPEXBuffer);
 
224
    if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
 
225
 
 
226
    {
 
227
        SETUP_VAR_REPLY(pexGetPredefinedEntriesReply);
 
228
        reply->numEntries = numEntries;
 
229
        WritePEXBufferReply(pexGetPredefinedEntriesReply);
 
230
    }
 
231
    return( err );
 
232
 
 
233
} /* end-PEXGetPredefinedEntries() */
 
234
 
 
235
/*++    PEXGetDefinedIndices
 
236
 --*/
 
237
 
 
238
ErrorCode
 
239
PEXGetDefinedIndices( cntxtPtr, strmPtr)
 
240
pexContext              *cntxtPtr;
 
241
pexGetDefinedIndicesReq *strmPtr;
 
242
{
 
243
    ErrorCode err = Success;
 
244
    diLUTHandle pf;
 
245
    extern ddBufferPtr pPEXBuffer;
 
246
    ddULONG numIndices = 0;
 
247
 
 
248
    LU_TABLE(strmPtr->id, pf);
 
249
 
 
250
    SETUP_INQ(pexGetDefinedIndicesReply);
 
251
 
 
252
    err = InquireLUTIndices( pf, &numIndices, pPEXBuffer);
 
253
    if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
 
254
 
 
255
    {
 
256
        SETUP_VAR_REPLY(pexGetDefinedIndicesReply);
 
257
        reply->numIndices = numIndices;
 
258
        WritePEXBufferReply(pexGetDefinedIndicesReply);
 
259
    }
 
260
    return( err );
 
261
 
 
262
} /* end-PEXGetDefinedIndices() */
 
263
 
 
264
/*++    PEXGetTableEntry
 
265
 --*/
 
266
 
 
267
ErrorCode
 
268
PEXGetTableEntry( cntxtPtr, strmPtr )
 
269
pexContext              *cntxtPtr;
 
270
pexGetTableEntryReq     *strmPtr;
 
271
{
 
272
    ErrorCode err = Success;
 
273
    diLUTHandle pf;
 
274
    extern ddBufferPtr pPEXBuffer;
 
275
    ddUSHORT status;
 
276
 
 
277
    LU_TABLE(strmPtr->lut, pf);
 
278
 
 
279
    SETUP_INQ(pexGetTableEntryReply);
 
280
 
 
281
    err = InquireLUTEntry(  pf, strmPtr->index, strmPtr->valueType,
 
282
                            &status, pPEXBuffer);
 
283
    if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
 
284
 
 
285
    /*
 
286
     * If this is a font table, we have to convert font handles to font ids.
 
287
     */
 
288
 
 
289
    if (pf->lutType == PEXTextFontLUT) {
 
290
        int i;
 
291
        pexTextFontEntry *ptfe = (pexTextFontEntry *)(pPEXBuffer->pBuf);
 
292
        pexFont *ptr = (pexFont *)(ptfe + 1);
 
293
        for (i=0; i<ptfe->numFonts; i++, ptr++)
 
294
            *ptr = ((diFontHandle) *ptr)->id;
 
295
    }
 
296
 
 
297
    {
 
298
        SETUP_VAR_REPLY(pexGetTableEntryReply);
 
299
        reply->status = status;
 
300
        reply->tableType = pf->lutType;
 
301
        WritePEXBufferReply(pexGetTableEntryReply);
 
302
    }
 
303
    return( err );
 
304
 
 
305
} /* end-PEXGetTableEntry() */
 
306
 
 
307
/*++    PEXGetTableEntries
 
308
 --*/
 
309
ErrorCode
 
310
PEXGetTableEntries( cntxtPtr, strmPtr )
 
311
pexContext              *cntxtPtr;
 
312
pexGetTableEntriesReq   *strmPtr;
 
313
{
 
314
    ErrorCode err = Success;
 
315
    diLUTHandle pf;
 
316
    ddULONG numEntries;
 
317
    extern ddBuffer *pPEXBuffer;
 
318
 
 
319
    LU_TABLE(strmPtr->lut, pf);
 
320
 
 
321
    SETUP_INQ(pexGetTableEntriesReply);
 
322
 
 
323
    err = InquireLUTEntries(    pf, strmPtr->start, strmPtr->count,
 
324
                                strmPtr->valueType, &numEntries, pPEXBuffer);
 
325
    if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
 
326
 
 
327
    /*
 
328
     * If this is a font table, we have to convert font handles to font ids.
 
329
     */
 
330
 
 
331
    if (pf->lutType == PEXTextFontLUT) {
 
332
        int i, j;
 
333
        pexTextFontEntry *ptfe = (pexTextFontEntry *)(pPEXBuffer->pBuf);
 
334
        for (i=0; i<strmPtr->count; i++) {
 
335
            pexFont *ptr = (pexFont *)(ptfe + 1);
 
336
            for (j=0; j<ptfe->numFonts; j++, ptr++)
 
337
                *ptr = ((diFontHandle) *ptr)->id;
 
338
            ptfe = (pexTextFontEntry *) ptr;
 
339
        }
 
340
    }
 
341
 
 
342
    {
 
343
        SETUP_VAR_REPLY(pexGetTableEntriesReply);
 
344
        reply->tableType = pf->lutType;
 
345
        reply->numEntries = numEntries;
 
346
        WritePEXBufferReply(pexGetTableEntriesReply);
 
347
    }
 
348
    return( err );
 
349
 
 
350
} /* end-PEXGetTableEntries() */
 
351
 
 
352
/*++    PEXSetTableEntries
 
353
 --*/
 
354
 
 
355
ErrorCode
 
356
PEXSetTableEntries( cntxtPtr, strmPtr )
 
357
pexContext              *cntxtPtr;
 
358
pexSetTableEntriesReq   *strmPtr;
 
359
{
 
360
    ErrorCode err = Success;
 
361
    diLUTHandle pf = 0;
 
362
 
 
363
    LU_TABLE(strmPtr->lut, pf);
 
364
    CHECK_FP_FORMAT(strmPtr->fpFormat);
 
365
 
 
366
    /*
 
367
        If this is a font table, lookup font id's and stuff pointers into
 
368
        the that longword, so ddpex gets its handles instead of ids.
 
369
     */
 
370
    if (pf->lutType == PEXTextFontLUT) {
 
371
        int i, j;
 
372
        diFontHandle fh;
 
373
        pexTextFontEntry *ptfe = (pexTextFontEntry *)(strmPtr + 1);
 
374
        for (i=0; i<strmPtr->count; i++) {
 
375
            pexFont *ptr = (pexFont *)(ptfe + 1);
 
376
            for (j=0; j<ptfe->numFonts; j++, ptr++) {
 
377
                LU_PEXFONT(*ptr, fh);
 
378
                *ptr = (pexFont) fh;
 
379
            }
 
380
            ptfe = (pexTextFontEntry *) ptr;
 
381
        }
 
382
    }
 
383
 
 
384
    err = SetLUTEntries(    pf, strmPtr->start, strmPtr->count,
 
385
                            (ddPointer)(strmPtr + 1));
 
386
    if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
 
387
    return( err );
 
388
 
 
389
} /* end-PEXSetTableEntries() */
 
390
 
 
391
/*++    PEXDeleteTableEntries
 
392
 --*/
 
393
 
 
394
ErrorCode
 
395
PEXDeleteTableEntries( cntxtPtr, strmPtr )
 
396
pexContext                      *cntxtPtr;
 
397
pexDeleteTableEntriesReq        *strmPtr;
 
398
{
 
399
    ErrorCode err = Success;
 
400
    diLUTHandle pf;
 
401
 
 
402
    LU_TABLE(strmPtr->lut, pf);
 
403
    err = DeleteLUTEntries (pf, strmPtr->start, strmPtr->count);
 
404
    if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
 
405
    return( err );
 
406
 
 
407
} /* end-PEXDeleteTableEntries() */
 
408
 
 
409
/*++    PEXChangeTableValues
 
410
 --*/
 
411
ErrorCode
 
412
PEXChangeTableValues (cntxtPtr, strmPtr)
 
413
pexContext              *cntxtPtr;      /* context pointer      */
 
414
pexChangeTableValuesReq *strmPtr;       /* stream pointer       */
 
415
{
 
416
    ErrorCode err = Success;
 
417
    diLUTHandle pf = 0;
 
418
 
 
419
    LU_TABLE(strmPtr->lut, pf);
 
420
    CHECK_FP_FORMAT(strmPtr->fpFormat);
 
421
 
 
422
    /*
 
423
        If this is a font table, lookup font id's and stuff pointers into
 
424
        the that longword, so ddpex gets its handles instead of ids.
 
425
     */
 
426
    if  ( (pf->lutType == PEXTextFontLUT) && 
 
427
          (strmPtr->TableMask == PEXLUTVTextFontGroup) )
 
428
    {
 
429
        int i, j;
 
430
        diFontHandle fh;
 
431
        pexTextFontEntry *ptfe = (pexTextFontEntry *)(strmPtr + 1);
 
432
            pexFont *ptr = (pexFont *)(ptfe + 1);
 
433
            for (j=0; j<ptfe->numFonts; j++, ptr++) {
 
434
                LU_PEXFONT(*ptr, fh);
 
435
                *ptr = (pexFont) fh;
 
436
            }
 
437
    }
 
438
 
 
439
    /* call to change table values routine goes here, this is a shell
 
440
        for this routine but should contain all necessary information
 
441
        to process the request
 
442
 
 
443
    err = ChangeTableValues ( pf, strmPtr->length, strmPtr->index,
 
444
                              strmPtr->TableMask, (ddPointer)(strmPtr + 1));
 
445
    */
 
446
    if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
 
447
    return( err );
 
448
 
 
449
} /* end-PEXChangeTableValues() */
 
450
 
 
451
/*++    PEXGetTableValues
 
452
 --*/
 
453
ErrorCode
 
454
PEXGetTableValues( cntxtPtr, strmPtr )
 
455
pexContext              *cntxtPtr;
 
456
pexGetTableValuesReq    *strmPtr;
 
457
{
 
458
    ErrorCode err = Success;
 
459
    diLUTHandle pf;
 
460
    ddULONG numValues;
 
461
    ddUSHORT status;
 
462
    extern ddBuffer *pPEXBuffer;
 
463
 
 
464
    CHECK_FP_FORMAT(strmPtr->fpFormat);
 
465
    LU_TABLE(strmPtr->lut, pf);
 
466
 
 
467
    SETUP_INQ(pexGetTableValuesReply);
 
468
 
 
469
    /* Place holder for ddpex interface
 
470
    err =  GetLUTValues( pf, strmPtr->index, strmPtr->TableMask,
 
471
                         strmPtr->valueType, &numValues, &status, pPEXBuffer);
 
472
    */
 
473
 
 
474
    if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
 
475
 
 
476
    /*
 
477
     * If this is a font table, we have to convert font handles to font ids.
 
478
     */
 
479
 
 
480
    if  ( (pf->lutType == PEXTextFontLUT) && 
 
481
          (strmPtr->TableMask == PEXLUTVTextFontGroup) )
 
482
    {
 
483
        int i, j;
 
484
        pexTextFontEntry *ptfe = (pexTextFontEntry *)(pPEXBuffer->pBuf);
 
485
            pexFont *ptr = (pexFont *)(ptfe + 1);
 
486
            for (j=0; j<ptfe->numFonts; j++, ptr++)
 
487
                *ptr = ((diFontHandle) *ptr)->id;
 
488
    }
 
489
 
 
490
    {
 
491
        SETUP_VAR_REPLY(pexGetTableValuesReply);
 
492
        reply->tableType = pf->lutType;
 
493
        reply->numValues = numValues;
 
494
        reply->status = status;
 
495
        WritePEXBufferReply(pexGetTableValuesReply);
 
496
    }
 
497
    return( err );
 
498
 
 
499
} /* end-PEXGetTableValues() */
 
500
/*++
 
501
 *
 
502
 *      End of File
 
503
 *
 
504
 --*/