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.15 2004/08/03 13:43:00 ekohl 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 VOID WINAPI
CreateCmdLink(VOID
);
49 /* GLOBALS ******************************************************************/
51 PSID DomainSid
= NULL
;
55 /* FUNCTIONS ****************************************************************/
58 DebugPrint(char* fmt
,...)
64 vsprintf(buffer
, fmt
, ap
);
67 strcat(buffer
, "\nRebooting now!");
79 PROCESS_INFORMATION ProcInfo
;
82 ZeroMemory(&si
, sizeof(STARTUPINFO
));
83 si
.cb
= sizeof(STARTUPINFO
);
85 if(CreateProcessA(NULL
, "vmwinst.exe", NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
,
86 NULL
, NULL
, &si
, &ProcInfo
))
88 WaitForSingleObject(ProcInfo
.hProcess
, INFINITE
);
89 CloseHandle(ProcInfo
.hThread
);
90 CloseHandle(ProcInfo
.hProcess
);
99 CreateRandomSid (PSID
*Sid
)
101 SID_IDENTIFIER_AUTHORITY SystemAuthority
= {SECURITY_NT_AUTHORITY
};
102 LARGE_INTEGER SystemTime
;
105 NtQuerySystemTime (&SystemTime
);
106 Seed
= &SystemTime
.u
.LowPart
;
108 RtlAllocateAndInitializeSid (&SystemAuthority
,
110 SECURITY_NT_NON_UNIQUE_RID
,
123 AppendRidToSid (PSID
*Dst
,
127 ULONG Rid
[8] = {0, 0, 0, 0, 0, 0, 0, 0};
131 RidCount
= *RtlSubAuthorityCountSid (Src
);
133 for (i
= 0; i
< RidCount
; i
++)
134 Rid
[i
] = *RtlSubAuthoritySid (Src
, i
);
138 Rid
[RidCount
] = NewRid
;
142 RtlAllocateAndInitializeSid (RtlIdentifierAuthoritySid (Src
),
156 RestartDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
161 SendDlgItemMessage(hWnd
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0,
163 SetTimer(hWnd
, 0, 50, NULL
);
171 hWndProgress
= GetDlgItem(hWnd
, IDC_RESTART_PROGRESS
);
172 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
176 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
195 CreateTempDir(LPCWSTR VarName
)
197 WCHAR szTempDir
[MAX_PATH
];
198 WCHAR szBuffer
[MAX_PATH
];
202 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE
,
203 L
"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
208 DebugPrint("Error: %lu\n", GetLastError());
213 dwLength
= MAX_PATH
* sizeof(WCHAR
);
214 if (RegQueryValueExW (hKey
,
221 DebugPrint("Error: %lu\n", GetLastError());
227 if (!ExpandEnvironmentStringsW (szBuffer
,
231 DebugPrint("Error: %lu\n", GetLastError());
236 /* Create profiles directory */
237 if (!CreateDirectoryW (szTempDir
, NULL
))
239 if (GetLastError () != ERROR_ALREADY_EXISTS
)
241 DebugPrint("Error: %lu\n", GetLastError());
250 #define SECTIONBUF_SIZE 4096
253 ProcessSysSetupInf(VOID
)
256 TCHAR szBuf
[SECTIONBUF_SIZE
];
261 dwBufSize
= GetPrivateProfileSection(_T("DeviceInfsToInstall"),
264 _T("Inf\\SYSSETUP.INF"));
266 /* fix this first... */
267 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
270 if (dwBufSize
== SECTIONBUF_SIZE
-2)
279 OutputDebugString(_T("Calling Class Installer for "));
280 OutputDebugString(pBuf2
);
281 OutputDebugString(_T("\r\n"));
284 /* FIXME: Currently unsupported */
285 if (!SetupDiInstallClass(NULL
, pBuf2
, DI_QUIETINSTALL
, NULL
))
288 pBuf2
+= _tcslen(pBuf2
) + 1;
296 InstallReactOS (HINSTANCE hInstance
)
299 OutputDebugStringA ("InstallReactOS() called\n");
301 if (!InitializeSetupActionLog (FALSE
))
303 OutputDebugStringA ("InitializeSetupActionLog() failed\n");
306 LogItem (SYSSETUP_SEVERITY_INFORMATION
,
307 L
"ReactOS Setup starting");
309 LogItem (SYSSETUP_SEVERITY_FATAL_ERROR
,
312 LogItem (SYSSETUP_SEVERITY_INFORMATION
,
313 L
"ReactOS Setup finished");
315 TerminateSetupActionLog ();
318 UNICODE_STRING SidString
;
321 if (!InitializeProfiles ())
323 DebugPrint ("InitializeProfiles() failed\n");
327 /* Create the semi-random Domain-SID */
328 CreateRandomSid (&DomainSid
);
329 if (DomainSid
== NULL
)
331 DebugPrint ("Domain-SID creation failed!\n");
336 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
337 DebugPrint ("Domain-SID: %wZ\n", &SidString
);
338 RtlFreeUnicodeString (&SidString
);
341 /* Initialize the Security Account Manager (SAM) */
342 if (!SamInitializeSAM ())
344 DebugPrint ("SamInitializeSAM() failed!\n");
345 RtlFreeSid (DomainSid
);
349 /* Set the Domain SID (aka Computer SID) */
350 if (!SamSetDomainSid (DomainSid
))
352 DebugPrint ("SamSetDomainSid() failed!\n");
353 RtlFreeSid (DomainSid
);
357 /* Append the Admin-RID */
358 AppendRidToSid (&AdminSid
, DomainSid
, DOMAIN_USER_RID_ADMIN
);
361 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
362 DebugPrint ("Admin-SID: %wZ\n", &SidString
);
363 RtlFreeUnicodeString (&SidString
);
366 /* Create the Administrator account */
367 if (!SamCreateUser (L
"Administrator", L
"", AdminSid
))
369 DebugPrint ("SamCreateUser() failed!\n");
370 RtlFreeSid (AdminSid
);
371 RtlFreeSid (DomainSid
);
375 /* Create the Administrator profile */
376 if (!CreateUserProfileW (AdminSid
, L
"Administrator"))
378 DebugPrint ("CreateUserProfileW() failed!\n");
379 RtlFreeSid (AdminSid
);
380 RtlFreeSid (DomainSid
);
384 RtlFreeSid (AdminSid
);
385 RtlFreeSid (DomainSid
);
387 CreateTempDir(L
"TEMP");
388 CreateTempDir(L
"TMP");
390 if(!ProcessSysSetupInf())
392 DebugPrint("ProcessSysSetupInf() failed!\n");
402 DialogBox (hDllInstance
,
403 MAKEINTRESOURCE(IDD_RESTART
),
415 SetupChangeFontSize(HANDLE hWnd
,
416 LPCWSTR lpszFontSize
)