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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/cfb/cfbwindow.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: cfbwindow.c,v 1.4 2001/02/09 02:04:39 xorgcvs Exp $ */
 
2
/***********************************************************
 
3
 
 
4
Copyright 1987, 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 in
 
13
all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
Except as contained in this notice, the name of The Open Group shall not be
 
23
used in advertising or otherwise to promote the sale, use or other dealings
 
24
in this Software without prior written authorization from The Open Group.
 
25
 
 
26
 
 
27
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
 
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 Digital not be
 
36
used in advertising or publicity pertaining to distribution of the
 
37
software without specific, written prior permission.  
 
38
 
 
39
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
40
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
41
DIGITAL 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
 
 
49
#include "X.h"
 
50
#include "scrnintstr.h"
 
51
#include "windowstr.h"
 
52
#include "cfb.h"
 
53
#include "mistruct.h"
 
54
#include "regionstr.h"
 
55
#include "cfbmskbits.h"
 
56
 
 
57
extern WindowPtr *WindowTable;
 
58
 
 
59
Bool
 
60
cfbCreateWindow(pWin)
 
61
    WindowPtr pWin;
 
62
{
 
63
    cfbPrivWin *pPrivWin;
 
64
 
 
65
    pPrivWin = cfbGetWindowPrivate(pWin);
 
66
    pPrivWin->pRotatedBorder = NullPixmap;
 
67
    pPrivWin->pRotatedBackground = NullPixmap;
 
68
    pPrivWin->fastBackground = FALSE;
 
69
    pPrivWin->fastBorder = FALSE;
 
70
    pPrivWin->oldRotate.x = 0;
 
71
    pPrivWin->oldRotate.y = 0;
 
72
 
 
73
#ifdef PIXMAP_PER_WINDOW
 
74
    /* Setup pointer to Screen pixmap */
 
75
    pWin->devPrivates[frameWindowPrivateIndex].ptr =
 
76
        (pointer) cfbGetScreenPixmap(pWin->drawable.pScreen);
 
77
#endif
 
78
 
 
79
    return TRUE;
 
80
}
 
81
 
 
82
Bool
 
83
cfbDestroyWindow(pWin)
 
84
    WindowPtr pWin;
 
85
{
 
86
    cfbPrivWin *pPrivWin;
 
87
 
 
88
    pPrivWin = cfbGetWindowPrivate(pWin);
 
89
 
 
90
    if (pPrivWin->pRotatedBorder)
 
91
        (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBorder);
 
92
    if (pPrivWin->pRotatedBackground)
 
93
        (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBackground);
 
94
    return(TRUE);
 
95
}
 
96
 
 
97
/*ARGSUSED*/
 
98
Bool
 
99
cfbMapWindow(pWindow)
 
100
    WindowPtr pWindow;
 
101
{
 
102
    return(TRUE);
 
103
}
 
104
 
 
105
/* (x, y) is the upper left corner of the window on the screen 
 
106
   do we really need to pass this?  (is it a;ready in pWin->absCorner?)
 
107
   we only do the rotation for pixmaps that are 32 bits wide (padded
 
108
or otherwise.)
 
109
   cfbChangeWindowAttributes() has already put a copy of the pixmap
 
110
in pPrivWin->pRotated*
 
111
*/
 
112
/*ARGSUSED*/
 
113
Bool
 
114
cfbPositionWindow(pWin, x, y)
 
115
    WindowPtr pWin;
 
116
    int x, y;
 
117
{
 
118
    cfbPrivWin *pPrivWin;
 
119
    int setxy = 0;
 
120
 
 
121
    pPrivWin = cfbGetWindowPrivate(pWin);
 
122
    if (pWin->backgroundState == BackgroundPixmap && pPrivWin->fastBackground)
 
123
    {
 
124
        cfbXRotatePixmap(pPrivWin->pRotatedBackground,
 
125
                      pWin->drawable.x - pPrivWin->oldRotate.x);
 
126
        cfbYRotatePixmap(pPrivWin->pRotatedBackground,
 
127
                      pWin->drawable.y - pPrivWin->oldRotate.y);
 
128
        setxy = 1;
 
129
    }
 
130
 
 
131
    if (!pWin->borderIsPixel && pPrivWin->fastBorder)
 
132
    {
 
133
        while (pWin->backgroundState == ParentRelative)
 
134
            pWin = pWin->parent;
 
135
        cfbXRotatePixmap(pPrivWin->pRotatedBorder,
 
136
                      pWin->drawable.x - pPrivWin->oldRotate.x);
 
137
        cfbYRotatePixmap(pPrivWin->pRotatedBorder,
 
138
                      pWin->drawable.y - pPrivWin->oldRotate.y);
 
139
        setxy = 1;
 
140
    }
 
141
    if (setxy)
 
142
    {
 
143
        pPrivWin->oldRotate.x = pWin->drawable.x;
 
144
        pPrivWin->oldRotate.y = pWin->drawable.y;
 
145
    }
 
146
    return (TRUE);
 
147
}
 
148
 
 
149
/*ARGSUSED*/
 
150
Bool
 
151
cfbUnmapWindow(pWindow)
 
152
    WindowPtr pWindow;
 
153
{
 
154
    return (TRUE);
 
155
}
 
156
 
 
157
/* UNCLEAN!
 
158
   this code calls the bitblt helper code directly.
 
159
 
 
160
   cfbCopyWindow copies only the parts of the destination that are
 
161
visible in the source.
 
162
*/
 
163
 
 
164
 
 
165
void 
 
166
cfbCopyWindow(pWin, ptOldOrg, prgnSrc)
 
167
    WindowPtr pWin;
 
168
    DDXPointRec ptOldOrg;
 
169
    RegionPtr prgnSrc;
 
170
{
 
171
    DDXPointPtr pptSrc;
 
172
    register DDXPointPtr ppt;
 
173
    RegionRec rgnDst;
 
174
    register BoxPtr pbox;
 
175
    register int dx, dy;
 
176
    register int i, nbox;
 
177
    WindowPtr pwinRoot;
 
178
 
 
179
    pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
 
180
 
 
181
    REGION_INIT(pWin->drawable.pScreen, &rgnDst, NullBox, 0);
 
182
 
 
183
    dx = ptOldOrg.x - pWin->drawable.x;
 
184
    dy = ptOldOrg.y - pWin->drawable.y;
 
185
    REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
 
186
    REGION_INTERSECT(pWin->drawable.pScreen, &rgnDst, &pWin->borderClip, prgnSrc);
 
187
 
 
188
    pbox = REGION_RECTS(&rgnDst);
 
189
    nbox = REGION_NUM_RECTS(&rgnDst);
 
190
    if(!nbox || !(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
 
191
    {
 
192
        REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
 
193
        return;
 
194
    }
 
195
    ppt = pptSrc;
 
196
 
 
197
    for (i = nbox; --i >= 0; ppt++, pbox++)
 
198
    {
 
199
        ppt->x = pbox->x1 + dx;
 
200
        ppt->y = pbox->y1 + dy;
 
201
    }
 
202
 
 
203
    cfbDoBitbltCopy((DrawablePtr)pwinRoot, (DrawablePtr)pwinRoot,
 
204
                GXcopy, &rgnDst, pptSrc, ~0L);
 
205
    DEALLOCATE_LOCAL(pptSrc);
 
206
    REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
 
207
}
 
208
 
 
209
 
 
210
 
 
211
/* swap in correct PaintWindow* routine.  If we can use a fast output
 
212
routine (i.e. the pixmap is paddable to 32 bits), also pre-rotate a copy
 
213
of it in devPrivates[cfbWindowPrivateIndex].ptr.
 
214
*/
 
215
Bool
 
216
cfbChangeWindowAttributes(pWin, mask)
 
217
    WindowPtr pWin;
 
218
    unsigned long mask;
 
219
{
 
220
    register unsigned long index;
 
221
    register cfbPrivWin *pPrivWin;
 
222
    int width;
 
223
    WindowPtr   pBgWin;
 
224
 
 
225
    pPrivWin = cfbGetWindowPrivate(pWin);
 
226
 
 
227
    /*
 
228
     * When background state changes from ParentRelative and
 
229
     * we had previously rotated the fast border pixmap to match
 
230
     * the parent relative origin, rerotate to match window
 
231
     */
 
232
    if (mask & (CWBackPixmap | CWBackPixel) &&
 
233
        pWin->backgroundState != ParentRelative &&
 
234
        pPrivWin->fastBorder &&
 
235
        (pPrivWin->oldRotate.x != pWin->drawable.x ||
 
236
         pPrivWin->oldRotate.y != pWin->drawable.y))
 
237
    {
 
238
        cfbXRotatePixmap(pPrivWin->pRotatedBorder,
 
239
                      pWin->drawable.x - pPrivWin->oldRotate.x);
 
240
        cfbYRotatePixmap(pPrivWin->pRotatedBorder,
 
241
                      pWin->drawable.y - pPrivWin->oldRotate.y);
 
242
        pPrivWin->oldRotate.x = pWin->drawable.x;
 
243
        pPrivWin->oldRotate.y = pWin->drawable.y;
 
244
    }
 
245
    while(mask)
 
246
    {
 
247
        index = lowbit (mask);
 
248
        mask &= ~index;
 
249
        switch(index)
 
250
        {
 
251
        case CWBackPixmap:
 
252
            if (pWin->backgroundState == None)
 
253
            {
 
254
                pPrivWin->fastBackground = FALSE;
 
255
            }
 
256
            else if (pWin->backgroundState == ParentRelative)
 
257
            {
 
258
                pPrivWin->fastBackground = FALSE;
 
259
                /* Rotate border to match parent origin */
 
260
                if (pPrivWin->pRotatedBorder) {
 
261
                    for (pBgWin = pWin->parent;
 
262
                         pBgWin->backgroundState == ParentRelative;
 
263
                         pBgWin = pBgWin->parent);
 
264
                    cfbXRotatePixmap(pPrivWin->pRotatedBorder,
 
265
                                  pBgWin->drawable.x - pPrivWin->oldRotate.x);
 
266
                    cfbYRotatePixmap(pPrivWin->pRotatedBorder,
 
267
                                  pBgWin->drawable.y - pPrivWin->oldRotate.y);
 
268
                    pPrivWin->oldRotate.x = pBgWin->drawable.x;
 
269
                    pPrivWin->oldRotate.y = pBgWin->drawable.y;
 
270
                }
 
271
            }
 
272
            else if (((width = (pWin->background.pixmap->drawable.width * PSZ))
 
273
                      <= PGSZ) && !(width & (width - 1)))
 
274
            {
 
275
                cfbCopyRotatePixmap(pWin->background.pixmap,
 
276
                                    &pPrivWin->pRotatedBackground,
 
277
                                    pWin->drawable.x,
 
278
                                    pWin->drawable.y);
 
279
                if (pPrivWin->pRotatedBackground)
 
280
                {
 
281
                    pPrivWin->fastBackground = TRUE;
 
282
                    pPrivWin->oldRotate.x = pWin->drawable.x;
 
283
                    pPrivWin->oldRotate.y = pWin->drawable.y;
 
284
                }
 
285
                else
 
286
                {
 
287
                    pPrivWin->fastBackground = FALSE;
 
288
                }
 
289
            }
 
290
            else
 
291
            {
 
292
                pPrivWin->fastBackground = FALSE;
 
293
            }
 
294
            break;
 
295
 
 
296
        case CWBackPixel:
 
297
            pPrivWin->fastBackground = FALSE;
 
298
            break;
 
299
 
 
300
        case CWBorderPixmap:
 
301
            if (((width = (pWin->border.pixmap->drawable.width * PSZ)) <= PGSZ) &&
 
302
                !(width & (width - 1)))
 
303
            {
 
304
                for (pBgWin = pWin;
 
305
                     pBgWin->backgroundState == ParentRelative;
 
306
                     pBgWin = pBgWin->parent);
 
307
                cfbCopyRotatePixmap(pWin->border.pixmap,
 
308
                                    &pPrivWin->pRotatedBorder,
 
309
                                    pBgWin->drawable.x,
 
310
                                    pBgWin->drawable.y);
 
311
                if (pPrivWin->pRotatedBorder)
 
312
                {
 
313
                    pPrivWin->fastBorder = TRUE;
 
314
                    pPrivWin->oldRotate.x = pBgWin->drawable.x;
 
315
                    pPrivWin->oldRotate.y = pBgWin->drawable.y;
 
316
                }
 
317
                else
 
318
                {
 
319
                    pPrivWin->fastBorder = FALSE;
 
320
                }
 
321
            }
 
322
            else
 
323
            {
 
324
                pPrivWin->fastBorder = FALSE;
 
325
            }
 
326
            break;
 
327
         case CWBorderPixel:
 
328
            pPrivWin->fastBorder = FALSE;
 
329
            break;
 
330
        }
 
331
    }
 
332
    return (TRUE);
 
333
}
 
334