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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/sun/sunFbs.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
/* $Xorg: sunFbs.c,v 1.4 2001/02/09 02:04:43 xorgcvs Exp $ */
 
3
 
 
4
/*
 
5
Copyright 1990, 1993, 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
 
 
28
/************************************************************
 
29
Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
 
30
 
 
31
                    All Rights Reserved
 
32
 
 
33
Permission  to  use,  copy,  modify,  and  distribute   this
 
34
software  and  its documentation for any purpose and without
 
35
fee is hereby granted, provided that the above copyright no-
 
36
tice  appear  in all copies and that both that copyright no-
 
37
tice and this permission notice appear in  supporting  docu-
 
38
mentation,  and  that the names of Sun or The Open Group
 
39
not be used in advertising or publicity pertaining to 
 
40
distribution  of  the software  without specific prior 
 
41
written permission. Sun and The Open Group make no 
 
42
representations about the suitability of this software for 
 
43
any purpose. It is provided "as is" without any express or 
 
44
implied warranty.
 
45
 
 
46
SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
 
47
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
 
48
NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
 
49
ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
50
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
 
51
PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
 
52
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
 
53
THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
54
 
 
55
********************************************************/
 
56
 
 
57
/*
 
58
 * Copyright 1987 by the Regents of the University of California
 
59
 * Copyright 1987 by Adam de Boor, UC Berkeley
 
60
 *
 
61
 * Permission to use, copy, modify, and distribute this
 
62
 * software and its documentation for any purpose and without
 
63
 * fee is hereby granted, provided that the above copyright
 
64
 * notice appear in all copies.  The University of California
 
65
 * makes no representations about the suitability of this
 
66
 * software for any purpose.  It is provided "as is" without
 
67
 * express or implied warranty.
 
68
 */
 
69
 
 
70
/* $XFree86: xc/programs/Xserver/hw/sun/sunFbs.c,v 1.7 2002/12/06 00:28:50 tsi Exp $ */
 
71
 
 
72
/****************************************************************/
 
73
/* Modified from  sunCG4C.c for X11R3 by Tom Jarmolowski        */
 
74
/****************************************************************/
 
75
 
 
76
#include "sun.h"
 
77
#include <sys/mman.h>
 
78
 
 
79
int sunScreenIndex;
 
80
 
 
81
static unsigned long generation = 0;
 
82
 
 
83
#if NeedFunctionPrototypes
 
84
pointer sunMemoryMap (
 
85
    size_t      len,
 
86
    off_t       off,
 
87
    int         fd)
 
88
#else
 
89
pointer sunMemoryMap (len, off, fd)
 
90
    size_t      len;
 
91
    off_t       off;
 
92
    int         fd;
 
93
#endif
 
94
{
 
95
    int         pagemask, mapsize;
 
96
    caddr_t     addr;
 
97
    pointer     mapaddr;
 
98
 
 
99
#ifdef SVR4
 
100
    pagemask = sysconf(_SC_PAGESIZE) - 1;
 
101
#else 
 
102
    pagemask = getpagesize() - 1;
 
103
#endif
 
104
    mapsize = ((int) len + pagemask) & ~pagemask;
 
105
    addr = 0;
 
106
 
 
107
#if !defined(__bsdi__) && !defined(_MAP_NEW) && !defined(__NetBSD__) && !defined(__OpenBSD__)
 
108
    if ((addr = (caddr_t) valloc (mapsize)) == NULL) {
 
109
        Error ("Couldn't allocate frame buffer memory");
 
110
        (void) close (fd);
 
111
        return NULL;
 
112
    }
 
113
#endif
 
114
 
 
115
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
 
116
    /* 
 
117
     * try and make it private first, that way once we get it, an
 
118
     * interloper, e.g. another server, can't get this frame buffer,
 
119
     * and if another server already has it, this one won't.
 
120
     */
 
121
    if ((int)(mapaddr = (pointer) mmap (addr,
 
122
                mapsize,
 
123
                PROT_READ | PROT_WRITE, MAP_PRIVATE,
 
124
                fd, off)) == -1)
 
125
#endif
 
126
        mapaddr = (pointer) mmap (addr,
 
127
                    mapsize,
 
128
                    PROT_READ | PROT_WRITE, MAP_SHARED,
 
129
                    fd, off);
 
130
    if (mapaddr == (pointer) -1) {
 
131
        Error ("mapping frame buffer memory");
 
132
        (void) close (fd);
 
133
        mapaddr = (pointer) NULL;
 
134
    }
 
135
    return mapaddr;
 
136
}
 
137
 
 
138
#if NeedFunctionPrototypes
 
139
Bool sunScreenAllocate (
 
140
    ScreenPtr   pScreen)
 
141
#else
 
142
Bool sunScreenAllocate (pScreen)
 
143
    ScreenPtr   pScreen;
 
144
#endif
 
145
{
 
146
    sunScreenPtr    pPrivate;
 
147
    extern int AllocateScreenPrivateIndex();
 
148
 
 
149
    if (generation != serverGeneration)
 
150
    {
 
151
        sunScreenIndex = AllocateScreenPrivateIndex();
 
152
        if (sunScreenIndex < 0)
 
153
            return FALSE;
 
154
        generation = serverGeneration;
 
155
    }
 
156
    pPrivate = (sunScreenPtr) xalloc (sizeof (sunScreenRec));
 
157
    if (!pPrivate)
 
158
        return FALSE;
 
159
 
 
160
    pScreen->devPrivates[sunScreenIndex].ptr = (pointer) pPrivate;
 
161
    return TRUE;
 
162
}
 
163
 
 
164
#if NeedFunctionPrototypes
 
165
Bool sunSaveScreen (
 
166
    ScreenPtr   pScreen,
 
167
    int         on)
 
168
#else
 
169
Bool sunSaveScreen (pScreen, on)
 
170
    ScreenPtr   pScreen;
 
171
    int         on;
 
172
#endif
 
173
{
 
174
    int         state;
 
175
 
 
176
    if (on != SCREEN_SAVER_FORCER)
 
177
    {
 
178
        if (on == SCREEN_SAVER_ON)
 
179
            state = 0;
 
180
        else
 
181
            state = 1;
 
182
        (void) ioctl(sunFbs[pScreen->myNum].fd, FBIOSVIDEO, &state);
 
183
    }
 
184
    return( TRUE );
 
185
}
 
186
 
 
187
static Bool closeScreen (i, pScreen)
 
188
    int         i;
 
189
    ScreenPtr   pScreen;
 
190
{
 
191
    SetupScreen(pScreen);
 
192
    Bool    ret;
 
193
 
 
194
    (void) OsSignal (SIGIO, SIG_IGN);
 
195
    sunDisableCursor (pScreen);
 
196
    pScreen->CloseScreen = pPrivate->CloseScreen;
 
197
    ret = (*pScreen->CloseScreen) (i, pScreen);
 
198
    (void) (*pScreen->SaveScreen) (pScreen, SCREEN_SAVER_OFF);
 
199
    xfree ((pointer) pPrivate);
 
200
    return ret;
 
201
}
 
202
 
 
203
#if NeedFunctionPrototypes
 
204
Bool sunScreenInit (
 
205
    ScreenPtr   pScreen)
 
206
#else
 
207
Bool sunScreenInit (pScreen)
 
208
    ScreenPtr   pScreen;
 
209
#endif
 
210
{
 
211
    SetupScreen(pScreen);
 
212
    extern void   sunBlockHandler();
 
213
    extern void   sunWakeupHandler();
 
214
    static ScreenPtr autoRepeatScreen;
 
215
    extern miPointerScreenFuncRec   sunPointerScreenFuncs;
 
216
 
 
217
    pPrivate->installedMap = 0;
 
218
    pPrivate->CloseScreen = pScreen->CloseScreen;
 
219
    pScreen->CloseScreen = closeScreen;
 
220
    pScreen->SaveScreen = sunSaveScreen;
 
221
#ifdef XKB
 
222
    if (noXkbExtension) {
 
223
#endif
 
224
    /*
 
225
     *  Block/Unblock handlers
 
226
     */
 
227
    if (sunAutoRepeatHandlersInstalled == FALSE) {
 
228
        autoRepeatScreen = pScreen;
 
229
        sunAutoRepeatHandlersInstalled = TRUE;
 
230
    }
 
231
 
 
232
    if (pScreen == autoRepeatScreen) {
 
233
        pScreen->BlockHandler = sunBlockHandler;
 
234
        pScreen->WakeupHandler = sunWakeupHandler;
 
235
    }
 
236
#ifdef XKB
 
237
    }
 
238
#endif
 
239
    if (!sunCursorInitialize (pScreen))
 
240
        miDCInitialize (pScreen, &sunPointerScreenFuncs);
 
241
    return TRUE;
 
242
}
 
243
 
 
244
#if NeedFunctionPrototypes
 
245
Bool sunInitCommon (
 
246
    int         scrn,
 
247
    ScreenPtr   pScrn,
 
248
    off_t       offset,
 
249
    Bool        (*init1)(),
 
250
    void        (*init2)(),
 
251
    Bool        (*cr_cm)(),
 
252
    Bool        (*save)(),
 
253
    int         fb_off)
 
254
#else
 
255
Bool sunInitCommon (scrn, pScrn, offset, init1, init2, cr_cm, save, fb_off)
 
256
    int         scrn;
 
257
    ScreenPtr   pScrn;
 
258
    off_t       offset;
 
259
    Bool        (*init1)();
 
260
    void        (*init2)();
 
261
    Bool        (*cr_cm)();
 
262
    Bool        (*save)();
 
263
    int         fb_off;
 
264
#endif
 
265
{
 
266
    unsigned char*      fb = sunFbs[scrn].fb;
 
267
 
 
268
    if (!sunScreenAllocate (pScrn))
 
269
        return FALSE;
 
270
    if (!fb) {
 
271
        if ((fb = sunMemoryMap ((size_t) sunFbs[scrn].info.fb_size, 
 
272
                             offset, 
 
273
                             sunFbs[scrn].fd)) == NULL)
 
274
            return FALSE;
 
275
        sunFbs[scrn].fb = fb;
 
276
    }
 
277
    /* mfbScreenInit() or cfbScreenInit() */
 
278
    if (!(*init1)(pScrn, fb + fb_off,
 
279
            sunFbs[scrn].info.fb_width,
 
280
            sunFbs[scrn].info.fb_height,
 
281
            monitorResolution, monitorResolution,
 
282
            sunFbs[scrn].info.fb_width,
 
283
            sunFbs[scrn].info.fb_depth))
 
284
            return FALSE;
 
285
    miInitializeBackingStore(pScrn);
 
286
    /* sunCGScreenInit() if cfb... */
 
287
    if (init2)
 
288
        (*init2)(pScrn);
 
289
    if (!sunScreenInit(pScrn))
 
290
        return FALSE;
 
291
    (void) (*save) (pScrn, SCREEN_SAVER_OFF);
 
292
    return (*cr_cm)(pScrn);
 
293
}
 
294