2 * Copyright (c) 2000, Red Hat, Inc.
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.
9 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
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. */
27 static const char *cvsid
=
47 #include "propsheet.h"
51 #include "AntiVirus.h"
61 #include "getopt++/GetOption.h"
62 #include "getopt++/BoolOption.h"
68 static BoolOption
UnattendedOption (false, 'q', "quiet-mode", "Unattended setup mode");
70 /* Maximum size of a SID on NT/W2K. */
71 #define MAX_SID_LEN 40
73 /* Computes the size of an ACL in relation to the number of ACEs it
75 #define TOKEN_ACL_SIZE(cnt) (sizeof(ACL) + \
76 (cnt) * (sizeof(ACCESS_ALLOWED_ACE) + MAX_SID_LEN))
78 #define iswinnt (GetVersion() < 0x80000000)
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
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)];
93 /* First initialize the TOKEN_DEFAULT_DACL structure. */
94 PTOKEN_DEFAULT_DACL dacl
= (PTOKEN_DEFAULT_DACL
) buf
;
95 dacl
->DefaultDacl
= (PACL
) (buf
+ sizeof *dacl
);
97 /* Initialize the ACL for containing one ACE. */
98 if (!InitializeAcl (dacl
->DefaultDacl
, TOKEN_ACL_SIZE (1), ACL_REVISION
))
100 log (LOG_TIMESTAMP
) << "InitializeAcl() failed: " << GetLastError ()
105 /* Get the SID for "Everyone". */
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
))
110 log (LOG_TIMESTAMP
) << "AllocateAndInitializeSid() failed: " <<
111 GetLastError () << endLog
;
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
))
120 log (LOG_TIMESTAMP
) << "AddAccessAllowedAce() failed: %lu" <<
121 GetLastError () << endLog
;
125 /* Get the processes access token. */
127 if (!OpenProcessToken (GetCurrentProcess (),
128 TOKEN_READ
| TOKEN_ADJUST_DEFAULT
, &token
))
130 log (LOG_TIMESTAMP
) << "OpenProcessToken() failed: "
131 << GetLastError () << endLog
;
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 ()
140 /* Close token handle. */
144 /* Free memory occupied by the "Everyone" SID. */
148 // Other threads talk to this page, so we need to have it externable.
149 ThreeBarProgressPage Progress
;
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).
158 WinMain (HINSTANCE h
,
159 HINSTANCE hPrevInstance
, LPSTR command_line
, int cmd_show
)
165 main (int argc
, char **argv
)
167 hinstance
= GetModuleHandle (NULL
);
170 char *cwd
=new char[_MAX_PATH
];
171 GetCurrentDirectory (_MAX_PATH
, cwd
);
172 local_dir
= String (cwd
);
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);
179 next_dialog
= IDD_SPLASH
;
181 log (LOG_PLAIN
) << "Starting cygwin install, version " << version
<< endLog
;
184 AntiVirusPage AntiVirus
;
187 LocalDirPage LocalDir
;
191 DesktopSetupPage Desktop
;
192 PropSheet MainWindow
;
194 log (LOG_TIMESTAMP
) << "Current Directory: " << local_dir
<< endLog
;
196 // TODO: make an equivalent for __argv under cygwin.
202 for (argc
= 0, _argv
= __argv
; *_argv
; _argv
++)++argc
;
205 // for (argc = 0, _argv = argv; *_argv; _argv++)++argc;
212 if (!GetOption::GetInstance().Process (argc
,_argv
))
216 unattended_mode
= UnattendedOption
;
218 /* Set the default DACL only on NT/W2K. 9x/ME has no idea of access
219 control lists and security at all. */
223 // Initialize common controls
224 InitCommonControls ();
226 // Init window class lib
227 Window::SetAppInstance (hinstance
);
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
);
253 // Create the PropSheet main window
254 MainWindow
.Create ();
257 /* Keep gcc happy :} */