3 * Copyright (C) 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: install.c,v 1.13 2004/06/24 09:17:33 gvg Exp $
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS system libraries
23 * PURPOSE: System setup
24 * FILE: lib/syssetup/install.c
25 * PROGRAMER: Eric Kohl (ekohl@rz-online.de)
28 /* INCLUDES *****************************************************************/
46 /* GLOBALS ******************************************************************/
48 PSID DomainSid
= NULL
;
52 /* FUNCTIONS ****************************************************************/
55 DebugPrint(char* fmt
,...)
61 vsprintf(buffer
, fmt
, ap
);
65 OutputDebugStringA(buffer
);
67 strcat (buffer
, "\nRebooting now!");
80 PROCESS_INFORMATION ProcInfo
;
83 ZeroMemory(&si
, sizeof(STARTUPINFO
));
84 si
.cb
= sizeof(STARTUPINFO
);
86 if(CreateProcessA(NULL
, "vmwinst.exe", NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
,
87 NULL
, NULL
, &si
, &ProcInfo
))
89 WaitForSingleObject(ProcInfo
.hProcess
, INFINITE
);
90 CloseHandle(ProcInfo
.hThread
);
91 CloseHandle(ProcInfo
.hProcess
);
100 CreateRandomSid (PSID
*Sid
)
102 SID_IDENTIFIER_AUTHORITY SystemAuthority
= {SECURITY_NT_AUTHORITY
};
103 LARGE_INTEGER SystemTime
;
106 NtQuerySystemTime (&SystemTime
);
107 Seed
= &SystemTime
.u
.LowPart
;
109 RtlAllocateAndInitializeSid (&SystemAuthority
,
111 SECURITY_NT_NON_UNIQUE_RID
,
124 AppendRidToSid (PSID
*Dst
,
128 ULONG Rid
[8] = {0, 0, 0, 0, 0, 0, 0, 0};
132 RidCount
= *RtlSubAuthorityCountSid (Src
);
134 for (i
= 0; i
< RidCount
; i
++)
135 Rid
[i
] = *RtlSubAuthoritySid (Src
, i
);
139 Rid
[RidCount
] = NewRid
;
143 RtlAllocateAndInitializeSid (RtlIdentifierAuthoritySid (Src
),
157 RestartDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
162 SendDlgItemMessage(hWnd
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0,
164 SetTimer(hWnd
, 0, 50, NULL
);
172 hWndProgress
= GetDlgItem(hWnd
, IDC_RESTART_PROGRESS
);
173 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
177 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
196 CreateTempDir(LPCWSTR VarName
)
198 WCHAR szTempDir
[MAX_PATH
];
199 WCHAR szBuffer
[MAX_PATH
];
203 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE
,
204 L
"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
209 DebugPrint("Error: %lu\n", GetLastError());
214 dwLength
= MAX_PATH
* sizeof(WCHAR
);
215 if (RegQueryValueExW (hKey
,
222 DebugPrint("Error: %lu\n", GetLastError());
228 if (!ExpandEnvironmentStringsW (szBuffer
,
232 DebugPrint("Error: %lu\n", GetLastError());
237 /* Create profiles directory */
238 if (!CreateDirectoryW (szTempDir
, NULL
))
240 if (GetLastError () != ERROR_ALREADY_EXISTS
)
242 DebugPrint("Error: %lu\n", GetLastError());
252 InstallReactOS (HINSTANCE hInstance
)
255 OutputDebugStringA ("InstallReactOS() called\n");
257 if (!InitializeSetupActionLog (FALSE
))
259 OutputDebugStringA ("InitializeSetupActionLog() failed\n");
262 LogItem (SYSSETUP_SEVERITY_INFORMATION
,
263 L
"ReactOS Setup starting");
265 LogItem (SYSSETUP_SEVERITY_FATAL_ERROR
,
268 LogItem (SYSSETUP_SEVERITY_INFORMATION
,
269 L
"ReactOS Setup finished");
271 TerminateSetupActionLog ();
274 UNICODE_STRING SidString
;
277 if (!InitializeProfiles ())
279 DebugPrint ("InitializeProfiles() failed\n");
283 /* Create the semi-random Domain-SID */
284 CreateRandomSid (&DomainSid
);
285 if (DomainSid
== NULL
)
287 DebugPrint ("Domain-SID creation failed!\n");
292 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
293 DebugPrint ("Domain-SID: %wZ\n", &SidString
);
294 RtlFreeUnicodeString (&SidString
);
297 /* Initialize the Security Account Manager (SAM) */
298 if (!SamInitializeSAM ())
300 DebugPrint ("SamInitializeSAM() failed!\n");
301 RtlFreeSid (DomainSid
);
305 /* Set the Domain SID (aka Computer SID) */
306 if (!SamSetDomainSid (DomainSid
))
308 DebugPrint ("SamSetDomainSid() failed!\n");
309 RtlFreeSid (DomainSid
);
313 /* Append the Admin-RID */
314 AppendRidToSid (&AdminSid
, DomainSid
, DOMAIN_USER_RID_ADMIN
);
317 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
318 DebugPrint ("Admin-SID: %wZ\n", &SidString
);
319 RtlFreeUnicodeString (&SidString
);
322 /* Create the Administrator account */
323 if (!SamCreateUser (L
"Administrator", L
"", AdminSid
))
325 DebugPrint ("SamCreateUser() failed!\n");
326 RtlFreeSid (AdminSid
);
327 RtlFreeSid (DomainSid
);
331 /* Create the Administrator profile */
332 if (!CreateUserProfileW (AdminSid
, L
"Administrator"))
334 DebugPrint ("CreateUserProfileW() failed!\n");
335 RtlFreeSid (AdminSid
);
336 RtlFreeSid (DomainSid
);
340 RtlFreeSid (AdminSid
);
341 RtlFreeSid (DomainSid
);
343 CreateTempDir(L
"TEMP");
344 CreateTempDir(L
"TMP");
354 DialogBox (hDllInstance
,
355 MAKEINTRESOURCE(IDD_RESTART
),
365 DWORD STDCALL
SetupChangeFontSize(HANDLE HWindow
,
366 LPCWSTR lpszFontSize
)