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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/darwin/quartz/quartzStartup.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
 *
 
3
 * Startup code for the Quartz Darwin X Server
 
4
 *
 
5
 **************************************************************/
 
6
/*
 
7
 * Copyright (c) 2001-2003 Torrey T. Lyons. All Rights Reserved.
 
8
 *
 
9
 * Permission is hereby granted, free of charge, to any person obtaining a
 
10
 * copy of this software and associated documentation files (the "Software"),
 
11
 * to deal in the Software without restriction, including without limitation
 
12
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
13
 * and/or sell copies of the Software, and to permit persons to whom the
 
14
 * Software is furnished to do so, subject to the following conditions:
 
15
 *
 
16
 * The above copyright notice and this permission notice shall be included in
 
17
 * all copies or substantial portions of the Software.
 
18
 *
 
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
22
 * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
23
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
24
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
25
 * DEALINGS IN THE SOFTWARE.
 
26
 *
 
27
 * Except as contained in this notice, the name(s) of the above copyright
 
28
 * holders shall not be used in advertising or otherwise to promote the sale,
 
29
 * use or other dealings in this Software without prior written authorization.
 
30
 */
 
31
/* $XFree86: xc/programs/Xserver/hw/darwin/quartz/quartzStartup.c,v 1.3 2003/01/19 06:35:13 torrey Exp $ */
 
32
 
 
33
#include <fcntl.h>
 
34
#include <unistd.h>
 
35
#include <CoreFoundation/CoreFoundation.h>
 
36
#include "quartzCommon.h"
 
37
#include "darwin.h"
 
38
#include "opaque.h"
 
39
#include "micmap.h"
 
40
 
 
41
int NSApplicationMain(int argc, char *argv[]);
 
42
 
 
43
char **envpGlobal;      // argcGlobal and argvGlobal
 
44
                        // are from dix/globals.c
 
45
 
 
46
// GLX bundle function pointers
 
47
typedef void (*GlxExtensionInitPtr)(void); 
 
48
static GlxExtensionInitPtr GlxExtensionInit = NULL;
 
49
 
 
50
typedef void (*GlxWrapInitVisualsPtr)(miInitVisualsProcPtr *);
 
51
static GlxWrapInitVisualsPtr GlxWrapInitVisuals = NULL;
 
52
 
 
53
 
 
54
/*
 
55
 * DarwinHandleGUI
 
56
 *  This function is called first from main(). The first time
 
57
 *  it is called we start the Mac OS X front end. The front end
 
58
 *  will call main() again from another thread to run the X
 
59
 *  server. On the second call this function loads the user
 
60
 *  preferences set by the Mac OS X front end.
 
61
 */
 
62
void DarwinHandleGUI(
 
63
    int         argc,
 
64
    char        *argv[],
 
65
    char        *envp[] )
 
66
{
 
67
    static Bool been_here = FALSE;
 
68
    int         main_exit, i;
 
69
    int         fd[2];
 
70
 
 
71
    if (been_here) {
 
72
        QuartzReadPreferences();
 
73
        return;
 
74
    }
 
75
    been_here = TRUE;
 
76
 
 
77
    // Make a pipe to pass events
 
78
    assert( pipe(fd) == 0 );
 
79
    darwinEventFD = fd[0];
 
80
    quartzEventWriteFD = fd[1];
 
81
    fcntl(darwinEventFD, F_SETFL, O_NONBLOCK);
 
82
 
 
83
    // Store command line arguments to pass back to main()
 
84
    argcGlobal = argc;
 
85
    argvGlobal = argv;
 
86
    envpGlobal = envp;
 
87
 
 
88
    // Determine if we need to start X clients
 
89
    // and what display mode to use
 
90
    quartzStartClients = 1;
 
91
    for (i = 1; i < argc; i++) {
 
92
        if (!strcmp(argv[i], "-nostartx")) {
 
93
            quartzStartClients = 0;    
 
94
        } else if (!strcmp( argv[i], "-fullscreen")) {
 
95
            quartzRootless = 0;
 
96
        } else if (!strcmp( argv[i], "-rootless")) {
 
97
            quartzRootless = 1;
 
98
        }
 
99
    }
 
100
 
 
101
    quartz = TRUE;
 
102
    main_exit = NSApplicationMain(argc, argv);
 
103
    exit(main_exit);
 
104
}
 
105
 
 
106
 
 
107
/*
 
108
 * LoadGlxBundle
 
109
 *  The Quartz mode X server needs to dynamically load the appropriate
 
110
 *  bundle before initializing GLX.
 
111
 */
 
112
static void LoadGlxBundle(void)
 
113
{
 
114
    CFBundleRef mainBundle;
 
115
    CFStringRef bundleName;
 
116
    CFURLRef    bundleURL;
 
117
    CFBundleRef glxBundle;
 
118
 
 
119
    // Get the main bundle for the application
 
120
    mainBundle = CFBundleGetMainBundle();
 
121
 
 
122
    // Choose the bundle to load
 
123
    ErrorF("Loading GLX bundle ");
 
124
    if (quartzUseAGL) {
 
125
        bundleName = CFSTR("glxAGL.bundle");
 
126
        ErrorF("glxAGL.bundle (using Apple's OpenGL)\n");
 
127
    } else {
 
128
        bundleName = CFSTR("glxMesa.bundle");
 
129
        ErrorF("glxMesa.bundle (using Mesa)\n");
 
130
    }
 
131
 
 
132
    // Look for the appropriate GLX bundle in the main bundle by name
 
133
    bundleURL = CFBundleCopyResourceURL(mainBundle, bundleName,
 
134
                                        NULL, NULL);
 
135
    if (!bundleURL) {
 
136
        FatalError("Could not find GLX bundle.");
 
137
    }
 
138
 
 
139
    // Make a bundle instance using the URLRef
 
140
    glxBundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);
 
141
 
 
142
    if (!CFBundleLoadExecutable(glxBundle)) {
 
143
        FatalError("Could not load GLX bundle.");
 
144
    }
 
145
 
 
146
    // Find the GLX init functions
 
147
    GlxExtensionInit = (void *) CFBundleGetFunctionPointerForName(
 
148
                                glxBundle, CFSTR("GlxExtensionInit"));
 
149
 
 
150
    GlxWrapInitVisuals = (void *) CFBundleGetFunctionPointerForName(
 
151
                                glxBundle, CFSTR("GlxWrapInitVisuals"));
 
152
 
 
153
    if (!GlxExtensionInit || !GlxWrapInitVisuals) {
 
154
        FatalError("Could not initialize GLX bundle.");
 
155
    }
 
156
 
 
157
    // Release the CF objects
 
158
    CFRelease(mainBundle);
 
159
    CFRelease(bundleURL);
 
160
}
 
161
 
 
162
 
 
163
/*
 
164
 * DarwinGlxExtensionInit
 
165
 *  Initialize the GLX extension.
 
166
 */
 
167
void DarwinGlxExtensionInit(void)
 
168
{
 
169
    if (!GlxExtensionInit)
 
170
        LoadGlxBundle();
 
171
 
 
172
    GlxExtensionInit();
 
173
}
 
174
 
 
175
 
 
176
/*
 
177
 * DarwinGlxWrapInitVisuals
 
178
 */
 
179
void DarwinGlxWrapInitVisuals(
 
180
    miInitVisualsProcPtr *procPtr)
 
181
{
 
182
    if (!GlxWrapInitVisuals)
 
183
        LoadGlxBundle();
 
184
 
 
185
    GlxWrapInitVisuals(procPtr);
 
186
}
 
187
 
 
188
 
 
189
int QuartzProcessArgument( int argc, char *argv[], int i )
 
190
{
 
191
    // fullscreen: CoreGraphics full-screen mode
 
192
    // rootless: Cocoa rootless mode
 
193
    // quartz: Default, either fullscreen or rootless
 
194
 
 
195
    if ( !strcmp( argv[i], "-fullscreen" ) ) {
 
196
        ErrorF( "Running full screen in parallel with Mac OS X Quartz window server.\n" );
 
197
#ifdef QUARTZ_SAFETY_DELAY
 
198
        ErrorF( "Quitting in %d seconds if no controller is found.\n",
 
199
                QUARTZ_SAFETY_DELAY );
 
200
#endif
 
201
        return 1;
 
202
    }
 
203
 
 
204
    if ( !strcmp( argv[i], "-rootless" ) ) {
 
205
        ErrorF( "Running rootless inside Mac OS X window server.\n" );
 
206
#ifdef QUARTZ_SAFETY_DELAY
 
207
        ErrorF( "Quitting in %d seconds if no controller is found.\n",
 
208
                QUARTZ_SAFETY_DELAY );
 
209
#endif
 
210
        return 1;
 
211
     }
 
212
 
 
213
    if ( !strcmp( argv[i], "-quartz" ) ) {
 
214
        ErrorF( "Running in parallel with Mac OS X Quartz window server.\n" );
 
215
#ifdef QUARTZ_SAFETY_DELAY
 
216
        ErrorF( "Quitting in %d seconds if no controller is found.\n",
 
217
                QUARTZ_SAFETY_DELAY );
 
218
#endif
 
219
        return 1;
 
220
    }
 
221
 
 
222
    // The Mac OS X front end uses this argument, which we just ignore here.
 
223
    if ( !strcmp( argv[i], "-nostartx" ) ) {
 
224
        return 1;
 
225
    }
 
226
 
 
227
    // This command line arg is passed when launched from the Aqua GUI.
 
228
    if ( !strncmp( argv[i], "-psn_", 5 ) ) {
 
229
        return 1;
 
230
    }
 
231
 
 
232
    return 0;
 
233
}
 
 
b'\\ No newline at end of file'