]> cygwin.com Git - cygwin-apps/setup.git/blob - main.cc
2002-11-25 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / main.cc
1 /*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16 /* OK, here's how this works. Each of the steps needed for install -
17 dialogs, downloads, installs - are in their own files and have some
18 "do_*" function (prototype in dialog.h) and a resource id (IDD_* or
19 IDD_S_* in resource.h) for that step. Each step is responsible for
20 selecting the next step! See the NEXT macro in dialog.h. Note
21 that the IDD_S_* ids are fake; those are for steps that don't
22 really have a controlling dialog (some have progress dialogs, but
23 those don't count, although they could). Replace the IDD_S_* with
24 IDD_* if you create a real dialog for those steps. */
25
26 #if 0
27 static const char *cvsid =
28 "\n%%% $Id$\n";
29 #endif
30
31 #include "win32.h"
32 #include <commctrl.h>
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include "resource.h"
37 #include "dialog.h"
38 #include "state.h"
39 #include "msg.h"
40 #include "find.h"
41 #include "mount.h"
42 #include "LogFile.h"
43 #include "version.h"
44
45 #include "port.h"
46 #include "proppage.h"
47 #include "propsheet.h"
48
49 // Page class headers
50 #include "splash.h"
51 #include "AntiVirus.h"
52 #include "source.h"
53 #include "root.h"
54 #include "localdir.h"
55 #include "net.h"
56 #include "site.h"
57 #include "choose.h"
58 #include "threebar.h"
59 #include "desktop.h"
60
61 #include "getopt++/GetOption.h"
62 #include "getopt++/BoolOption.h"
63
64 int next_dialog;
65
66 HINSTANCE hinstance;
67
68 static BoolOption UnattendedOption (false, 'q', "quiet-mode", "Unattended setup mode");
69
70 /* Maximum size of a SID on NT/W2K. */
71 #define MAX_SID_LEN 40
72
73 /* Computes the size of an ACL in relation to the number of ACEs it
74 should contain. */
75 #define TOKEN_ACL_SIZE(cnt) (sizeof(ACL) + \
76 (cnt) * (sizeof(ACCESS_ALLOWED_ACE) + MAX_SID_LEN))
77
78 #define iswinnt (GetVersion() < 0x80000000)
79
80 void
81 set_default_dacl ()
82 {
83 /* To assure that the created files have a useful ACL, the
84 default DACL in the process token is set to full access to
85 everyone. This applies to files and subdirectories created
86 in directories which don't propagate permissions to child
87 objects. */
88
89 /* Create a buffer which has enough room to contain the TOKEN_DEFAULT_DACL
90 structure plus an ACL with one ACE. */
91 char buf[sizeof (TOKEN_DEFAULT_DACL) + TOKEN_ACL_SIZE (1)];
92
93 /* First initialize the TOKEN_DEFAULT_DACL structure. */
94 PTOKEN_DEFAULT_DACL dacl = (PTOKEN_DEFAULT_DACL) buf;
95 dacl->DefaultDacl = (PACL) (buf + sizeof *dacl);
96
97 /* Initialize the ACL for containing one ACE. */
98 if (!InitializeAcl (dacl->DefaultDacl, TOKEN_ACL_SIZE (1), ACL_REVISION))
99 {
100 log (LOG_TIMESTAMP) << "InitializeAcl() failed: " << GetLastError ()
101 << endLog;
102 return;
103 }
104
105 /* Get the SID for "Everyone". */
106 PSID sid;
107 SID_IDENTIFIER_AUTHORITY sid_auth = { SECURITY_WORLD_SID_AUTHORITY };
108 if (!AllocateAndInitializeSid (&sid_auth, 1, 0, 0, 0, 0, 0, 0, 0, 0, &sid))
109 {
110 log (LOG_TIMESTAMP) << "AllocateAndInitializeSid() failed: " <<
111 GetLastError () << endLog;
112 return;
113 }
114
115 /* Create the ACE which grants full access to "Everyone" and store it
116 in dacl->DefaultDacl. */
117 if (!AddAccessAllowedAce
118 (dacl->DefaultDacl, ACL_REVISION, GENERIC_ALL, sid))
119 {
120 log (LOG_TIMESTAMP) << "AddAccessAllowedAce() failed: %lu" <<
121 GetLastError () << endLog;
122 goto out;
123 }
124
125 /* Get the processes access token. */
126 HANDLE token;
127 if (!OpenProcessToken (GetCurrentProcess (),
128 TOKEN_READ | TOKEN_ADJUST_DEFAULT, &token))
129 {
130 log (LOG_TIMESTAMP) << "OpenProcessToken() failed: "
131 << GetLastError () << endLog;
132 goto out;
133 }
134
135 /* Set the default DACL to the above computed ACL. */
136 if (!SetTokenInformation (token, TokenDefaultDacl, dacl, sizeof buf))
137 log (LOG_TIMESTAMP) << "OpenProcessToken() failed: " << GetLastError ()
138 << endLog;
139
140 /* Close token handle. */
141 CloseHandle (token);
142
143 out:
144 /* Free memory occupied by the "Everyone" SID. */
145 FreeSid (sid);
146 }
147
148 // Other threads talk to this page, so we need to have it externable.
149 ThreeBarProgressPage Progress;
150
151 // This is a little ugly, but the decision about where to log occurs
152 // after the source is set AND the root mount obtained
153 // so we make the actual logger available to the appropriate routine(s).
154 LogFile *theLog;
155
156 #ifndef __CYGWIN__
157 int WINAPI
158 WinMain (HINSTANCE h,
159 HINSTANCE hPrevInstance, LPSTR command_line, int cmd_show)
160 {
161
162 hinstance = h;
163 #else
164 int
165 main (int argc, char **argv)
166 {
167 hinstance = GetModuleHandle (NULL);
168 #endif
169
170 char *cwd=new char[_MAX_PATH];
171 GetCurrentDirectory (_MAX_PATH, cwd);
172 local_dir = String (cwd);
173 delete cwd;
174
175 LogSingleton::SetInstance (*(theLog = LogFile::createLogFile()));
176 theLog->setFile (LOG_BABBLE, local_dir + "/setup.log.full", false);
177 theLog->setFile (0, local_dir + "/setup.log", true);
178
179 next_dialog = IDD_SPLASH;
180
181 log (LOG_PLAIN) << "Starting cygwin install, version " << version << endLog;
182
183 SplashPage Splash;
184 AntiVirusPage AntiVirus;
185 SourcePage Source;
186 RootPage Root;
187 LocalDirPage LocalDir;
188 NetPage Net;
189 SitePage Site;
190 ChooserPage Chooser;
191 DesktopSetupPage Desktop;
192 PropSheet MainWindow;
193
194 log (LOG_TIMESTAMP) << "Current Directory: " << local_dir << endLog;
195
196 // TODO: make an equivalent for __argv under cygwin.
197 char **_argv;
198 #ifndef __CYGWIN__
199 int argc;
200 // char **_argv;
201 #ifndef __CYGWIN__
202 for (argc = 0, _argv = __argv; *_argv; _argv++)++argc;
203 _argv = __argv;
204 #else
205 // for (argc = 0, _argv = argv; *_argv; _argv++)++argc;
206 _argv = argv;
207 #endif
208 #else
209 _argv = argv;
210 #endif
211
212 if (!GetOption::GetInstance().Process (argc,_argv))
213 theLog->exit(1);
214 // #endif
215
216 unattended_mode = UnattendedOption;
217
218 /* Set the default DACL only on NT/W2K. 9x/ME has no idea of access
219 control lists and security at all. */
220 if (iswinnt)
221 set_default_dacl ();
222
223 // Initialize common controls
224 InitCommonControls ();
225
226 // Init window class lib
227 Window::SetAppInstance (hinstance);
228
229 // Create pages
230 Splash.Create ();
231 AntiVirus.Create ();
232 Source.Create ();
233 Root.Create ();
234 LocalDir.Create ();
235 Net.Create ();
236 Site.Create ();
237 Chooser.Create ();
238 Progress.Create ();
239 Desktop.Create ();
240
241 // Add pages to sheet
242 MainWindow.AddPage (&Splash);
243 MainWindow.AddPage (&AntiVirus);
244 MainWindow.AddPage (&Source);
245 MainWindow.AddPage (&Root);
246 MainWindow.AddPage (&LocalDir);
247 MainWindow.AddPage (&Net);
248 MainWindow.AddPage (&Site);
249 MainWindow.AddPage (&Chooser);
250 MainWindow.AddPage (&Progress);
251 MainWindow.AddPage (&Desktop);
252
253 // Create the PropSheet main window
254 MainWindow.Create ();
255
256 theLog->exit (0);
257 /* Keep gcc happy :} */
258 return 0;
259 }
This page took 0.045949 seconds and 5 git commands to generate.