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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xwin/winwindow.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
 *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
 
3
 *
 
4
 *Permission is hereby granted, free of charge, to any person obtaining
 
5
 * a copy of this software and associated documentation files (the
 
6
 *"Software"), to deal in the Software without restriction, including
 
7
 *without limitation the rights to use, copy, modify, merge, publish,
 
8
 *distribute, sublicense, and/or sell copies of the Software, and to
 
9
 *permit persons to whom the Software is furnished to do so, subject to
 
10
 *the following conditions:
 
11
 *
 
12
 *The above copyright notice and this permission notice shall be
 
13
 *included in all copies or substantial portions of the Software.
 
14
 *
 
15
 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
16
 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
17
 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
18
 *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
 
19
 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 
20
 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
21
 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 *
 
23
 *Except as contained in this notice, the name of the XFree86 Project
 
24
 *shall not be used in advertising or otherwise to promote the sale, use
 
25
 *or other dealings in this Software without prior written authorization
 
26
 *from the XFree86 Project.
 
27
 *
 
28
 * Authors:     Harold L Hunt II
 
29
 *              Kensuke Matsuzaki
 
30
 */
 
31
/* $XFree86: xc/programs/Xserver/hw/xwin/winwindow.c,v 1.6 2003/02/12 15:01:38 alanh Exp $ */
 
32
 
 
33
#include "win.h"
 
34
 
 
35
/*
 
36
 * Prototypes for local functions
 
37
 */
 
38
 
 
39
static int
 
40
winAddRgn (WindowPtr pWindow, pointer data);
 
41
 
 
42
static
 
43
void
 
44
winUpdateRgn (WindowPtr pWindow);
 
45
 
 
46
#ifdef SHAPE
 
47
static
 
48
void
 
49
winReshape (WindowPtr pWin);
 
50
#endif
 
51
 
 
52
 
 
53
/* See Porting Layer Definition - p. 37 */
 
54
/* See mfb/mfbwindow.c - mfbCreateWindow() */
 
55
 
 
56
Bool
 
57
winCreateWindowNativeGDI (WindowPtr pWin)
 
58
{
 
59
  ErrorF ("winCreateWindowNativeGDI ()\n");
 
60
  return TRUE;
 
61
}
 
62
 
 
63
 
 
64
/* See Porting Layer Definition - p. 37 */
 
65
/* See mfb/mfbwindow.c - mfbDestroyWindow() */
 
66
 
 
67
Bool
 
68
winDestroyWindowNativeGDI (WindowPtr pWin)
 
69
{
 
70
  ErrorF ("winDestroyWindowNativeGDI ()\n");
 
71
  return TRUE;
 
72
}
 
73
 
 
74
 
 
75
/* See Porting Layer Definition - p. 37 */
 
76
/* See mfb/mfbwindow.c - mfbPositionWindow() */
 
77
 
 
78
Bool
 
79
winPositionWindowNativeGDI (WindowPtr pWin, int x, int y)
 
80
{
 
81
  ErrorF ("winPositionWindowNativeGDI ()\n");
 
82
  return TRUE;
 
83
}
 
84
 
 
85
 
 
86
/* See Porting Layer Definition - p. 39 */
 
87
/* See mfb/mfbwindow.c - mfbCopyWindow() */
 
88
 
 
89
void 
 
90
winCopyWindowNativeGDI (WindowPtr pWin,
 
91
                        DDXPointRec ptOldOrg,
 
92
                        RegionPtr prgnSrc)
 
93
{
 
94
  ErrorF ("winCopyWindowNativeGDI ()\n");
 
95
}
 
96
 
 
97
 
 
98
/* See Porting Layer Definition - p. 37 */
 
99
/* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */
 
100
 
 
101
Bool
 
102
winChangeWindowAttributesNativeGDI (WindowPtr pWin, unsigned long mask)
 
103
{
 
104
  ErrorF ("winChangeWindowAttributesNativeGDI ()\n");
 
105
  return TRUE;
 
106
}
 
107
 
 
108
 
 
109
/* See Porting Layer Definition - p. 37
 
110
 * Also referred to as UnrealizeWindow
 
111
 */
 
112
 
 
113
Bool
 
114
winUnmapWindowNativeGDI (WindowPtr pWindow)
 
115
{
 
116
  ErrorF ("winUnmapWindowNativeGDI ()\n");
 
117
  /* This functions is empty in the CFB,
 
118
   * we probably won't need to do anything
 
119
   */
 
120
  return TRUE;
 
121
}
 
122
 
 
123
 
 
124
/* See Porting Layer Definition - p. 37
 
125
 * Also referred to as RealizeWindow
 
126
 */
 
127
 
 
128
Bool
 
129
winMapWindowNativeGDI (WindowPtr pWindow)
 
130
{
 
131
  ErrorF ("winMapWindowNativeGDI ()\n");
 
132
  /* This function is empty in the CFB,
 
133
   * we probably won't need to do anything
 
134
   */
 
135
  return TRUE;
 
136
 
 
137
}
 
138
 
 
139
 
 
140
/* See Porting Layer Definition - p. 37 */
 
141
/* See mfb/mfbwindow.c - mfbCreateWindow() */
 
142
 
 
143
Bool
 
144
winCreateWindowPRootless (WindowPtr pWin)
 
145
{
 
146
  Bool                  fResult = FALSE;
 
147
  winWindowPriv(pWin);
 
148
 
 
149
#if CYGDEBUG
 
150
  ErrorF ("winCreateWindowPRootless ()\n");
 
151
#endif
 
152
 
 
153
  fResult = winGetScreenPriv(pWin->drawable.pScreen)->CreateWindow(pWin);
 
154
  
 
155
  pWinPriv->hRgn = NULL;
 
156
  /*winUpdateRgn (pWin);*/
 
157
  
 
158
  return fResult;
 
159
}
 
160
 
 
161
 
 
162
/* See Porting Layer Definition - p. 37 */
 
163
/* See mfb/mfbwindow.c - mfbDestroyWindow() */
 
164
 
 
165
Bool
 
166
winDestroyWindowPRootless (WindowPtr pWin)
 
167
{
 
168
  Bool                  fResult = FALSE;
 
169
  winWindowPriv(pWin);
 
170
 
 
171
#if CYGDEBUG
 
172
  ErrorF ("winDestroyWindowPRootless ()\n");
 
173
#endif
 
174
 
 
175
  fResult = winGetScreenPriv(pWin->drawable.pScreen)->DestroyWindow(pWin);
 
176
  
 
177
  if (pWinPriv->hRgn != NULL)
 
178
    {
 
179
      DeleteObject(pWinPriv->hRgn);
 
180
      pWinPriv->hRgn = NULL;
 
181
    }
 
182
  
 
183
  winUpdateRgn (pWin);
 
184
  
 
185
  return fResult;
 
186
}
 
187
 
 
188
 
 
189
/* See Porting Layer Definition - p. 37 */
 
190
/* See mfb/mfbwindow.c - mfbPositionWindow() */
 
191
 
 
192
Bool
 
193
winPositionWindowPRootless (WindowPtr pWin, int x, int y)
 
194
{
 
195
  Bool                  fResult = FALSE;
 
196
 
 
197
#if CYGDEBUG
 
198
  ErrorF ("winPositionWindowPRootless ()\n");
 
199
#endif
 
200
 
 
201
  fResult = winGetScreenPriv(pWin->drawable.pScreen)->PositionWindow(pWin, x, y);
 
202
  
 
203
  winUpdateRgn (pWin);
 
204
  
 
205
  return fResult;
 
206
}
 
207
 
 
208
 
 
209
/* See Porting Layer Definition - p. 37 */
 
210
/* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */
 
211
 
 
212
Bool
 
213
winChangeWindowAttributesPRootless (WindowPtr pWin, unsigned long mask)
 
214
{
 
215
  Bool                  fResult = FALSE;
 
216
 
 
217
#if CYGDEBUG
 
218
  ErrorF ("winChangeWindowAttributesPRootless ()\n");
 
219
#endif
 
220
 
 
221
  fResult = winGetScreenPriv(pWin->drawable.pScreen)->ChangeWindowAttributes(pWin, mask);
 
222
  
 
223
  winUpdateRgn (pWin);
 
224
  
 
225
  return fResult;
 
226
}
 
227
 
 
228
 
 
229
/* See Porting Layer Definition - p. 37
 
230
 * Also referred to as UnrealizeWindow
 
231
 */
 
232
 
 
233
Bool
 
234
winUnmapWindowPRootless (WindowPtr pWin)
 
235
{
 
236
  Bool                  fResult = FALSE;
 
237
  winWindowPriv(pWin);
 
238
 
 
239
#if CYGDEBUG
 
240
  ErrorF ("winUnmapWindowPRootless ()\n");
 
241
#endif
 
242
 
 
243
  fResult = winGetScreenPriv(pWin->drawable.pScreen)->UnrealizeWindow(pWin);
 
244
  
 
245
  if (pWinPriv->hRgn != NULL)
 
246
    {
 
247
      DeleteObject(pWinPriv->hRgn);
 
248
      pWinPriv->hRgn = NULL;
 
249
    }
 
250
  
 
251
  winUpdateRgn (pWin);
 
252
  
 
253
  return fResult;
 
254
}
 
255
 
 
256
 
 
257
/* See Porting Layer Definition - p. 37
 
258
 * Also referred to as RealizeWindow
 
259
 */
 
260
 
 
261
Bool
 
262
winMapWindowPRootless (WindowPtr pWin)
 
263
{
 
264
  Bool                  fResult = FALSE;
 
265
 
 
266
#if CYGDEBUG
 
267
  ErrorF ("winMapWindowPRootless ()\n");
 
268
#endif
 
269
 
 
270
  fResult = winGetScreenPriv(pWin->drawable.pScreen)->RealizeWindow(pWin);
 
271
  
 
272
  winReshape (pWin);
 
273
  
 
274
  winUpdateRgn (pWin);
 
275
  
 
276
  return fResult;
 
277
}
 
278
 
 
279
 
 
280
#ifdef SHAPE
 
281
void
 
282
winSetShapePRootless (WindowPtr pWin)
 
283
{
 
284
#if CYGDEBUG
 
285
  ErrorF ("winSetShapePRootless ()\n");
 
286
#endif
 
287
 
 
288
  winGetScreenPriv(pWin->drawable.pScreen)->SetShape(pWin);
 
289
  
 
290
  winReshape (pWin);
 
291
  winUpdateRgn (pWin);
 
292
  
 
293
  return;
 
294
}
 
295
#endif
 
296
 
 
297
 
 
298
/*
 
299
 * Local function for adding a region to the Windows window region
 
300
 */
 
301
 
 
302
static
 
303
int
 
304
winAddRgn (WindowPtr pWin, pointer data)
 
305
{
 
306
  int           iX, iY, iWidth, iHeight, iBorder;
 
307
  HRGN          hRgn = *(HRGN*)data;
 
308
  HRGN          hRgnWin;
 
309
  winWindowPriv(pWin);
 
310
  
 
311
  /* If pWin is not Root */
 
312
  if (pWin->parent != NULL) 
 
313
    {
 
314
#if CYGDEBUG
 
315
      ErrorF ("winAddRgn ()\n");
 
316
#endif
 
317
      if (pWin->mapped)
 
318
        {
 
319
          iBorder = wBorderWidth (pWin);
 
320
          
 
321
          iX = pWin->drawable.x - iBorder;
 
322
          iY = pWin->drawable.y - iBorder;
 
323
          
 
324
          iWidth = pWin->drawable.width + iBorder * 2;
 
325
          iHeight = pWin->drawable.height + iBorder * 2;
 
326
          
 
327
          hRgnWin = CreateRectRgn (0, 0, iWidth, iHeight);
 
328
          
 
329
          if (hRgnWin == NULL)
 
330
            {
 
331
              ErrorF ("winAddRgn - CreateRectRgn () failed\n");
 
332
              ErrorF ("  Rect %d %d %d %d\n",
 
333
                      iX, iY, iX + iWidth, iY + iHeight);
 
334
            }
 
335
          
 
336
          if (pWinPriv->hRgn)
 
337
            {
 
338
              if (CombineRgn (hRgnWin, hRgnWin, pWinPriv->hRgn, RGN_AND)
 
339
                  == ERROR)
 
340
                {
 
341
                  ErrorF ("winAddRgn - CombineRgn () failed\n");
 
342
                }
 
343
            }
 
344
          
 
345
          OffsetRgn (hRgnWin, iX, iY);
 
346
 
 
347
          if (CombineRgn (hRgn, hRgn, hRgnWin, RGN_OR) == ERROR)
 
348
            {
 
349
              ErrorF ("winAddRgn - CombineRgn () failed\n");
 
350
            }
 
351
          
 
352
          DeleteObject (hRgnWin);
 
353
        }
 
354
      return WT_DONTWALKCHILDREN;
 
355
    }
 
356
  else
 
357
    {
 
358
      return WT_WALKCHILDREN;
 
359
    }
 
360
}
 
361
 
 
362
 
 
363
/*
 
364
 * Local function to update the Windows window's region
 
365
 */
 
366
 
 
367
static
 
368
void
 
369
winUpdateRgn (WindowPtr pWin)
 
370
{
 
371
  HRGN          hRgn = CreateRectRgn (0, 0, 0, 0);
 
372
  
 
373
  if (hRgn != NULL)
 
374
    {
 
375
      WalkTree (pWin->drawable.pScreen, winAddRgn, &hRgn);
 
376
      SetWindowRgn (winGetScreenPriv(pWin->drawable.pScreen)->hwndScreen,
 
377
                    hRgn, TRUE);
 
378
    }
 
379
  else
 
380
    {
 
381
      ErrorF ("winUpdateRgn - CreateRectRgn failed.\n");
 
382
    }
 
383
}
 
384
 
 
385
 
 
386
#ifdef SHAPE
 
387
static
 
388
void
 
389
winReshape (WindowPtr pWin)
 
390
{
 
391
  int           nRects;
 
392
  ScreenPtr     pScreen = pWin->drawable.pScreen;
 
393
  RegionRec     rrNewShape;
 
394
  BoxPtr        pShape, pRects, pEnd;
 
395
  HRGN          hRgn, hRgnRect;
 
396
  winWindowPriv(pWin);
 
397
 
 
398
#if CYGDEBUG
 
399
  ErrorF ("winReshape ()\n");
 
400
#endif
 
401
 
 
402
  /* Bail if the window is the root window */
 
403
  if (pWin->parent == NULL)
 
404
    return;
 
405
 
 
406
  /* Bail if the window is not top level */
 
407
  if (pWin->parent->parent != NULL)
 
408
    return;
 
409
 
 
410
  /* Free any existing window region stored in the window privates */
 
411
  if (pWinPriv->hRgn != NULL)
 
412
    {
 
413
      DeleteObject (pWinPriv->hRgn);
 
414
      pWinPriv->hRgn = NULL;
 
415
    }
 
416
  
 
417
  /* Bail if the window has no bounding region defined */
 
418
  if (!wBoundingShape (pWin))
 
419
    return;
 
420
 
 
421
  REGION_INIT(pScreen, &rrNewShape, NullBox, 0);
 
422
  REGION_COPY(pScreen, &rrNewShape, wBoundingShape(pWin));
 
423
  REGION_TRANSLATE(pScreen, &rrNewShape, pWin->borderWidth,
 
424
                   pWin->borderWidth);
 
425
  
 
426
  nRects = REGION_NUM_RECTS(&rrNewShape);
 
427
  pShape = REGION_RECTS(&rrNewShape);
 
428
  
 
429
  if (nRects > 0)
 
430
    {
 
431
      /* Create initial empty Windows region */
 
432
      hRgn = CreateRectRgn (0, 0, 0, 0);
 
433
 
 
434
      /* Loop through all rectangles in the X region */
 
435
      for (pRects = pShape, pEnd = pShape + nRects; pRects < pEnd; pRects++)
 
436
        {
 
437
          /* Create a Windows region for the X rectangle */
 
438
          hRgnRect = CreateRectRgn (pRects->x1, pRects->y1,
 
439
                                    pRects->x2, pRects->y2);
 
440
          if (hRgnRect == NULL)
 
441
            {
 
442
              ErrorF("winReshape - CreateRectRgn() failed\n");
 
443
            }
 
444
 
 
445
          /* Merge the Windows region with the accumulated region */
 
446
          if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR)
 
447
            {
 
448
              ErrorF("winReshape - CombineRgn() failed\n");
 
449
            }
 
450
 
 
451
          /* Delete the temporary Windows region */
 
452
          DeleteObject (hRgnRect);
 
453
        }
 
454
      
 
455
      /* Save a handle to the composite region in the window privates */
 
456
      pWinPriv->hRgn = hRgn;
 
457
    }
 
458
 
 
459
  REGION_UNINIT(pScreen, &rrNewShape);
 
460
  
 
461
  return;
 
462
}
 
463
#endif