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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/darwin/quartz/pseudoramiX.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
 * Minimal implementation of PanoramiX/Xinerama
 
3
 *
 
4
 * This is used in rootless mode where the underlying window server
 
5
 * already provides an abstracted view of multiple screens as one
 
6
 * large screen area.
 
7
 *
 
8
 * This code is largely based on panoramiX.c, which contains the
 
9
 * following copyright notice:
 
10
 */
 
11
/*****************************************************************
 
12
Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
 
13
Permission is hereby granted, free of charge, to any person obtaining a copy
 
14
of this software and associated documentation files (the "Software"), to deal
 
15
in the Software without restriction, including without limitation the rights
 
16
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
17
copies of the Software.
 
18
 
 
19
The above copyright notice and this permission notice shall be included in
 
20
all copies or substantial portions of the Software.
 
21
 
 
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
25
DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
 
26
BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
 
27
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
 
28
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
29
 
 
30
Except as contained in this notice, the name of Digital Equipment Corporation
 
31
shall not be used in advertising or otherwise to promote the sale, use or other
 
32
dealings in this Software without prior written authorization from Digital
 
33
Equipment Corporation.
 
34
******************************************************************/
 
35
/* $XFree86: xc/programs/Xserver/hw/darwin/quartz/pseudoramiX.c,v 1.2 2002/10/16 21:13:33 dawes Exp $ */
 
36
 
 
37
#include "pseudoramiX.h"
 
38
 
 
39
#include "extnsionst.h"
 
40
#include "dixstruct.h"
 
41
#include "window.h"
 
42
#include "panoramiXproto.h"
 
43
#include "globals.h"
 
44
 
 
45
extern int ProcPanoramiXQueryVersion (ClientPtr client);
 
46
 
 
47
static void PseudoramiXResetProc(ExtensionEntry *extEntry);
 
48
 
 
49
static int ProcPseudoramiXQueryVersion(ClientPtr client);
 
50
static int ProcPseudoramiXGetState(ClientPtr client);
 
51
static int ProcPseudoramiXGetScreenCount(ClientPtr client);
 
52
static int ProcPseudoramiXGetScreenSize(ClientPtr client);
 
53
static int ProcPseudoramiXIsActive(ClientPtr client);
 
54
static int ProcPseudoramiXQueryScreens(ClientPtr client);
 
55
static int ProcPseudoramiXDispatch(ClientPtr client);
 
56
 
 
57
static int SProcPseudoramiXQueryVersion(ClientPtr client);
 
58
static int SProcPseudoramiXGetState(ClientPtr client);
 
59
static int SProcPseudoramiXGetScreenCount(ClientPtr client);
 
60
static int SProcPseudoramiXGetScreenSize(ClientPtr client);
 
61
static int SProcPseudoramiXIsActive(ClientPtr client);
 
62
static int SProcPseudoramiXQueryScreens(ClientPtr client);
 
63
static int SProcPseudoramiXDispatch(ClientPtr client);
 
64
 
 
65
 
 
66
typedef struct {
 
67
    int x;
 
68
    int y;
 
69
    int w;
 
70
    int h;
 
71
} PseudoramiXScreenRec;
 
72
 
 
73
static PseudoramiXScreenRec *pseudoramiXScreens = NULL;
 
74
static int pseudoramiXScreensAllocated = 0;
 
75
static int pseudoramiXNumScreens = 0;
 
76
static unsigned long pseudoramiXGeneration = 0;
 
77
 
 
78
 
 
79
// Add a PseudoramiX screen.
 
80
// The rest of the X server will know nothing about this screen.
 
81
// Can be called before or after extension init.
 
82
// Screens must be re-added once per generation.
 
83
void
 
84
PseudoramiXAddScreen(int x, int y, int w, int h)
 
85
{
 
86
    PseudoramiXScreenRec *s;
 
87
 
 
88
    if (noPseudoramiXExtension) return;
 
89
 
 
90
    if (pseudoramiXNumScreens == pseudoramiXScreensAllocated) {
 
91
        pseudoramiXScreensAllocated += pseudoramiXScreensAllocated + 1;
 
92
        pseudoramiXScreens = xrealloc(pseudoramiXScreens,
 
93
                                      pseudoramiXScreensAllocated *
 
94
                                      sizeof(PseudoramiXScreenRec));
 
95
    }
 
96
 
 
97
    s = &pseudoramiXScreens[pseudoramiXNumScreens++];
 
98
    s->x = x;
 
99
    s->y = y;
 
100
    s->w = w;
 
101
    s->h = h;
 
102
}
 
103
 
 
104
 
 
105
// Initialize PseudoramiX.
 
106
// Copied from PanoramiXExtensionInit
 
107
void PseudoramiXExtensionInit(int argc, char *argv[])
 
108
{
 
109
    Bool                success = FALSE;
 
110
    ExtensionEntry      *extEntry;
 
111
 
 
112
    if (noPseudoramiXExtension) return;
 
113
 
 
114
    if (pseudoramiXNumScreens == 1  ||  aquaNumScreens == 1) {
 
115
        // Only one screen - disable Xinerama extension.
 
116
        noPseudoramiXExtension = TRUE;
 
117
        return;
 
118
    }
 
119
 
 
120
    // The server must not run the PanoramiX operations.
 
121
    noPanoramiXExtension = TRUE;
 
122
 
 
123
    if (pseudoramiXGeneration != serverGeneration) {
 
124
        extEntry = AddExtension(PANORAMIX_PROTOCOL_NAME, 0, 0,
 
125
                                ProcPseudoramiXDispatch,
 
126
                                SProcPseudoramiXDispatch,
 
127
                                PseudoramiXResetProc,
 
128
                                StandardMinorOpcode);
 
129
        if (!extEntry) {
 
130
            ErrorF("PseudoramiXExtensionInit(): AddExtension failed\n");
 
131
        } else {
 
132
            pseudoramiXGeneration = serverGeneration;
 
133
            success = TRUE;
 
134
        }
 
135
    }
 
136
 
 
137
    if (!success) {
 
138
        ErrorF("%s Extension (PseudoramiX) failed to initialize\n",
 
139
               PANORAMIX_PROTOCOL_NAME);
 
140
        return;
 
141
    }
 
142
}
 
143
 
 
144
 
 
145
static void PseudoramiXResetProc(ExtensionEntry *extEntry)
 
146
{
 
147
    pseudoramiXNumScreens = 0;
 
148
}
 
149
 
 
150
 
 
151
// was PanoramiX
 
152
static int ProcPseudoramiXQueryVersion(ClientPtr client)
 
153
{
 
154
    return ProcPanoramiXQueryVersion(client);
 
155
}
 
156
 
 
157
 
 
158
// was PanoramiX
 
159
static int ProcPseudoramiXGetState(ClientPtr client)
 
160
{
 
161
    REQUEST(xPanoramiXGetStateReq);
 
162
    WindowPtr pWin;
 
163
    xPanoramiXGetStateReply rep;
 
164
    register int n;
 
165
 
 
166
    REQUEST_SIZE_MATCH(xPanoramiXGetStateReq);
 
167
    pWin = LookupWindow (stuff->window, client);
 
168
    if (!pWin)
 
169
        return BadWindow;
 
170
    rep.type = X_Reply;
 
171
    rep.length = 0;
 
172
    rep.sequenceNumber = client->sequence;
 
173
    rep.state = !noPseudoramiXExtension;
 
174
    if (client->swapped) {
 
175
        swaps (&rep.sequenceNumber, n);
 
176
        swapl (&rep.length, n);
 
177
        swaps (&rep.state, n);
 
178
    }
 
179
    WriteToClient (client, sizeof (xPanoramiXGetStateReply), (char *) &rep);
 
180
    return client->noClientException;
 
181
}
 
182
 
 
183
 
 
184
// was PanoramiX
 
185
static int ProcPseudoramiXGetScreenCount(ClientPtr client)
 
186
{
 
187
    REQUEST(xPanoramiXGetScreenCountReq);
 
188
    WindowPtr pWin;
 
189
    xPanoramiXGetScreenCountReply rep;
 
190
    register int n;
 
191
 
 
192
    REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq);
 
193
    pWin = LookupWindow (stuff->window, client);
 
194
    if (!pWin)
 
195
        return BadWindow;
 
196
    rep.type = X_Reply;
 
197
    rep.length = 0;
 
198
    rep.sequenceNumber = client->sequence;
 
199
    rep.ScreenCount = pseudoramiXNumScreens;
 
200
    if (client->swapped) {
 
201
        swaps (&rep.sequenceNumber, n);
 
202
        swapl (&rep.length, n);
 
203
        swaps (&rep.ScreenCount, n);
 
204
    }
 
205
    WriteToClient (client, sizeof(xPanoramiXGetScreenCountReply), (char *)&rep);
 
206
    return client->noClientException;
 
207
}
 
208
 
 
209
 
 
210
// was PanoramiX
 
211
static int ProcPseudoramiXGetScreenSize(ClientPtr client)
 
212
{
 
213
    REQUEST(xPanoramiXGetScreenSizeReq);
 
214
    WindowPtr                   pWin;
 
215
    xPanoramiXGetScreenSizeReply        rep;
 
216
    register int                        n;
 
217
 
 
218
    REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq);
 
219
    pWin = LookupWindow (stuff->window, client);
 
220
    if (!pWin)
 
221
        return BadWindow;
 
222
    rep.type = X_Reply;
 
223
    rep.length = 0;
 
224
    rep.sequenceNumber = client->sequence;
 
225
    /* screen dimensions */
 
226
    rep.width  = pseudoramiXScreens[stuff->screen].w;
 
227
    // was panoramiXdataPtr[stuff->screen].width;
 
228
    rep.height = pseudoramiXScreens[stuff->screen].h;
 
229
    // was panoramiXdataPtr[stuff->screen].height;
 
230
    if (client->swapped) {
 
231
        swaps (&rep.sequenceNumber, n);
 
232
        swapl (&rep.length, n);
 
233
        swaps (&rep.width, n);
 
234
        swaps (&rep.height, n);
 
235
    }
 
236
    WriteToClient (client, sizeof(xPanoramiXGetScreenSizeReply), (char *)&rep);
 
237
    return client->noClientException;
 
238
}
 
239
 
 
240
 
 
241
// was Xinerama
 
242
static int ProcPseudoramiXIsActive(ClientPtr client)
 
243
{
 
244
    /* REQUEST(xXineramaIsActiveReq); */
 
245
    xXineramaIsActiveReply      rep;
 
246
 
 
247
    REQUEST_SIZE_MATCH(xXineramaIsActiveReq);
 
248
 
 
249
    rep.type = X_Reply;
 
250
    rep.length = 0;
 
251
    rep.sequenceNumber = client->sequence;
 
252
    rep.state = !noPseudoramiXExtension;
 
253
    if (client->swapped) {
 
254
        register int n;
 
255
        swaps (&rep.sequenceNumber, n);
 
256
        swapl (&rep.length, n);
 
257
        swapl (&rep.state, n);
 
258
    }
 
259
    WriteToClient (client, sizeof (xXineramaIsActiveReply), (char *) &rep);
 
260
    return client->noClientException;
 
261
}
 
262
 
 
263
 
 
264
// was Xinerama
 
265
static int ProcPseudoramiXQueryScreens(ClientPtr client)
 
266
{
 
267
    /* REQUEST(xXineramaQueryScreensReq); */
 
268
    xXineramaQueryScreensReply  rep;
 
269
 
 
270
    REQUEST_SIZE_MATCH(xXineramaQueryScreensReq);
 
271
 
 
272
    rep.type = X_Reply;
 
273
    rep.sequenceNumber = client->sequence;
 
274
    rep.number = noPseudoramiXExtension ? 0 : pseudoramiXNumScreens;
 
275
    rep.length = rep.number * sz_XineramaScreenInfo >> 2;
 
276
    if (client->swapped) {
 
277
        register int n;
 
278
        swaps (&rep.sequenceNumber, n);
 
279
        swapl (&rep.length, n);
 
280
        swapl (&rep.number, n);
 
281
    }
 
282
    WriteToClient (client, sizeof (xXineramaQueryScreensReply), (char *) &rep);
 
283
 
 
284
    if (!noPseudoramiXExtension) {
 
285
        xXineramaScreenInfo scratch;
 
286
        int i;
 
287
 
 
288
        for(i = 0; i < pseudoramiXNumScreens; i++) {
 
289
            scratch.x_org  = pseudoramiXScreens[i].x;
 
290
            scratch.y_org  = pseudoramiXScreens[i].y;
 
291
            scratch.width  = pseudoramiXScreens[i].w;
 
292
            scratch.height = pseudoramiXScreens[i].h;
 
293
 
 
294
            if(client->swapped) {
 
295
                register int n;
 
296
                swaps (&scratch.x_org, n);
 
297
                swaps (&scratch.y_org, n);
 
298
                swaps (&scratch.width, n);
 
299
                swaps (&scratch.height, n);
 
300
            }
 
301
            WriteToClient (client, sz_XineramaScreenInfo, (char *) &scratch);
 
302
        }
 
303
    }
 
304
 
 
305
    return client->noClientException;
 
306
}
 
307
 
 
308
 
 
309
// was PanoramiX
 
310
static int ProcPseudoramiXDispatch (ClientPtr client)
 
311
{   REQUEST(xReq);
 
312
    switch (stuff->data)
 
313
    {
 
314
        case X_PanoramiXQueryVersion:
 
315
             return ProcPseudoramiXQueryVersion(client);
 
316
        case X_PanoramiXGetState:
 
317
             return ProcPseudoramiXGetState(client);
 
318
        case X_PanoramiXGetScreenCount:
 
319
             return ProcPseudoramiXGetScreenCount(client);
 
320
        case X_PanoramiXGetScreenSize:
 
321
             return ProcPseudoramiXGetScreenSize(client);
 
322
        case X_XineramaIsActive:
 
323
             return ProcPseudoramiXIsActive(client);
 
324
        case X_XineramaQueryScreens:
 
325
             return ProcPseudoramiXQueryScreens(client);
 
326
    }
 
327
    return BadRequest;
 
328
}
 
329
 
 
330
 
 
331
 
 
332
static int
 
333
SProcPseudoramiXQueryVersion (ClientPtr client)
 
334
{
 
335
        REQUEST(xPanoramiXQueryVersionReq);
 
336
        register int n;
 
337
 
 
338
        swaps(&stuff->length,n);
 
339
        REQUEST_SIZE_MATCH (xPanoramiXQueryVersionReq);
 
340
        return ProcPseudoramiXQueryVersion(client);
 
341
}
 
342
 
 
343
static int
 
344
SProcPseudoramiXGetState(ClientPtr client)
 
345
{
 
346
        REQUEST(xPanoramiXGetStateReq);
 
347
        register int n;
 
348
 
 
349
        swaps (&stuff->length, n);
 
350
        REQUEST_SIZE_MATCH(xPanoramiXGetStateReq);
 
351
        return ProcPseudoramiXGetState(client);
 
352
}
 
353
 
 
354
static int
 
355
SProcPseudoramiXGetScreenCount(ClientPtr client)
 
356
{
 
357
        REQUEST(xPanoramiXGetScreenCountReq);
 
358
        register int n;
 
359
 
 
360
        swaps (&stuff->length, n);
 
361
        REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq);
 
362
        return ProcPseudoramiXGetScreenCount(client);
 
363
}
 
364
 
 
365
static int
 
366
SProcPseudoramiXGetScreenSize(ClientPtr client)
 
367
{
 
368
        REQUEST(xPanoramiXGetScreenSizeReq);
 
369
        register int n;
 
370
 
 
371
        swaps (&stuff->length, n);
 
372
        REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq);
 
373
        return ProcPseudoramiXGetScreenSize(client);
 
374
}
 
375
 
 
376
 
 
377
static int
 
378
SProcPseudoramiXIsActive(ClientPtr client)
 
379
{
 
380
        REQUEST(xXineramaIsActiveReq);
 
381
        register int n;
 
382
 
 
383
        swaps (&stuff->length, n);
 
384
        REQUEST_SIZE_MATCH(xXineramaIsActiveReq);
 
385
        return ProcPseudoramiXIsActive(client);
 
386
}
 
387
 
 
388
 
 
389
static int
 
390
SProcPseudoramiXQueryScreens(ClientPtr client)
 
391
{
 
392
        REQUEST(xXineramaQueryScreensReq);
 
393
        register int n;
 
394
 
 
395
        swaps (&stuff->length, n);
 
396
        REQUEST_SIZE_MATCH(xXineramaQueryScreensReq);
 
397
        return ProcPseudoramiXQueryScreens(client);
 
398
}
 
399
 
 
400
 
 
401
static int
 
402
SProcPseudoramiXDispatch (ClientPtr client)
 
403
{   REQUEST(xReq);
 
404
    switch (stuff->data)
 
405
    {
 
406
        case X_PanoramiXQueryVersion:
 
407
             return SProcPseudoramiXQueryVersion(client);
 
408
        case X_PanoramiXGetState:
 
409
             return SProcPseudoramiXGetState(client);
 
410
        case X_PanoramiXGetScreenCount:
 
411
             return SProcPseudoramiXGetScreenCount(client);
 
412
        case X_PanoramiXGetScreenSize:
 
413
             return SProcPseudoramiXGetScreenSize(client);
 
414
        case X_XineramaIsActive:
 
415
             return SProcPseudoramiXIsActive(client);
 
416
        case X_XineramaQueryScreens:
 
417
             return SProcPseudoramiXQueryScreens(client);
 
418
    }
 
419
    return BadRequest;
 
420
}