2003-05-02 18:12:38 +00:00
|
|
|
/*
|
|
|
|
* ReactOS kernel
|
|
|
|
* Copyright (C) 2003 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
2004-10-19 14:33:07 +00:00
|
|
|
/* $Id: install.c,v 1.17 2004/10/19 14:33:07 ekohl Exp $
|
2003-05-02 18:12:38 +00:00
|
|
|
*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* PURPOSE: System setup
|
|
|
|
* FILE: lib/syssetup/install.c
|
2004-08-28 11:08:50 +00:00
|
|
|
* PROGRAMER: Eric Kohl
|
2003-05-02 18:12:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2004-01-16 21:33:23 +00:00
|
|
|
#include <ntos.h>
|
2003-05-02 18:12:38 +00:00
|
|
|
#include <windows.h>
|
2004-03-21 14:37:19 +00:00
|
|
|
#include <commctrl.h>
|
2004-01-16 21:33:23 +00:00
|
|
|
#include <stdio.h>
|
2004-07-19 01:33:48 +00:00
|
|
|
#include <tchar.h>
|
|
|
|
#include <stdlib.h>
|
2003-05-02 18:12:38 +00:00
|
|
|
|
2004-01-23 10:35:52 +00:00
|
|
|
#include <samlib.h>
|
2003-05-02 18:12:38 +00:00
|
|
|
#include <syssetup.h>
|
2004-04-19 10:54:23 +00:00
|
|
|
#include <userenv.h>
|
2004-08-28 11:08:50 +00:00
|
|
|
#include <setupapi.h>
|
2003-05-02 18:12:38 +00:00
|
|
|
|
2004-04-16 13:37:18 +00:00
|
|
|
#include "globals.h"
|
2004-03-21 14:37:19 +00:00
|
|
|
#include "resource.h"
|
|
|
|
|
2004-04-09 18:27:11 +00:00
|
|
|
#define VMWINST
|
2004-01-23 10:35:52 +00:00
|
|
|
|
2004-08-03 13:43:00 +00:00
|
|
|
VOID WINAPI CreateCmdLink(VOID);
|
|
|
|
|
2004-01-09 20:05:04 +00:00
|
|
|
|
2004-01-16 21:33:23 +00:00
|
|
|
/* GLOBALS ******************************************************************/
|
|
|
|
|
|
|
|
PSID DomainSid = NULL;
|
|
|
|
PSID AdminSid = NULL;
|
|
|
|
|
2004-08-28 11:08:50 +00:00
|
|
|
HINF hSysSetupInf = INVALID_HANDLE_VALUE;
|
2004-01-09 20:05:04 +00:00
|
|
|
|
2003-05-02 18:12:38 +00:00
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2004-01-16 21:33:23 +00:00
|
|
|
void
|
|
|
|
DebugPrint(char* fmt,...)
|
|
|
|
{
|
2004-01-23 16:51:41 +00:00
|
|
|
char buffer[512];
|
2004-01-16 21:33:23 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf(buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
2004-08-03 13:43:00 +00:00
|
|
|
strcat(buffer, "\nRebooting now!");
|
|
|
|
MessageBoxA(NULL,
|
|
|
|
buffer,
|
|
|
|
"ReactOS Setup",
|
|
|
|
MB_OK);
|
2004-01-16 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
2004-04-19 10:54:23 +00:00
|
|
|
|
2004-04-09 18:27:11 +00:00
|
|
|
#ifdef VMWINST
|
|
|
|
static BOOL
|
|
|
|
RunVMWInstall(VOID)
|
|
|
|
{
|
|
|
|
PROCESS_INFORMATION ProcInfo;
|
|
|
|
STARTUPINFO si;
|
|
|
|
|
|
|
|
ZeroMemory(&si, sizeof(STARTUPINFO));
|
|
|
|
si.cb = sizeof(STARTUPINFO);
|
|
|
|
|
|
|
|
if(CreateProcessA(NULL, "vmwinst.exe", NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
|
|
|
|
NULL, NULL, &si, &ProcInfo))
|
|
|
|
{
|
|
|
|
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
|
|
|
|
CloseHandle(ProcInfo.hThread);
|
|
|
|
CloseHandle(ProcInfo.hProcess);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-01-16 21:33:23 +00:00
|
|
|
|
|
|
|
static VOID
|
|
|
|
CreateRandomSid (PSID *Sid)
|
|
|
|
{
|
|
|
|
SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY};
|
|
|
|
LARGE_INTEGER SystemTime;
|
|
|
|
PULONG Seed;
|
|
|
|
|
|
|
|
NtQuerySystemTime (&SystemTime);
|
|
|
|
Seed = &SystemTime.u.LowPart;
|
|
|
|
|
|
|
|
RtlAllocateAndInitializeSid (&SystemAuthority,
|
|
|
|
4,
|
|
|
|
SECURITY_NT_NON_UNIQUE_RID,
|
|
|
|
RtlUniform (Seed),
|
|
|
|
RtlUniform (Seed),
|
|
|
|
RtlUniform (Seed),
|
|
|
|
SECURITY_NULL_RID,
|
|
|
|
SECURITY_NULL_RID,
|
|
|
|
SECURITY_NULL_RID,
|
|
|
|
SECURITY_NULL_RID,
|
|
|
|
Sid);
|
|
|
|
}
|
|
|
|
|
2004-01-23 10:35:52 +00:00
|
|
|
|
2004-01-16 21:33:23 +00:00
|
|
|
static VOID
|
|
|
|
AppendRidToSid (PSID *Dst,
|
|
|
|
PSID Src,
|
|
|
|
ULONG NewRid)
|
|
|
|
{
|
|
|
|
ULONG Rid[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
UCHAR RidCount;
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
RidCount = *RtlSubAuthorityCountSid (Src);
|
|
|
|
|
|
|
|
for (i = 0; i < RidCount; i++)
|
|
|
|
Rid[i] = *RtlSubAuthoritySid (Src, i);
|
|
|
|
|
|
|
|
if (RidCount < 8)
|
|
|
|
{
|
|
|
|
Rid[RidCount] = NewRid;
|
|
|
|
RidCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlAllocateAndInitializeSid (RtlIdentifierAuthoritySid (Src),
|
|
|
|
RidCount,
|
|
|
|
Rid[0],
|
|
|
|
Rid[1],
|
|
|
|
Rid[2],
|
|
|
|
Rid[3],
|
|
|
|
Rid[4],
|
|
|
|
Rid[5],
|
|
|
|
Rid[6],
|
|
|
|
Rid[7],
|
|
|
|
Dst);
|
|
|
|
}
|
|
|
|
|
2004-03-21 14:37:19 +00:00
|
|
|
INT_PTR CALLBACK
|
|
|
|
RestartDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch(msg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
SendDlgItemMessage(hWnd, IDC_RESTART_PROGRESS, PBM_SETRANGE, 0,
|
|
|
|
MAKELPARAM(0, 300));
|
|
|
|
SetTimer(hWnd, 0, 50, NULL);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_TIMER:
|
|
|
|
{
|
|
|
|
INT Position;
|
|
|
|
HWND hWndProgress;
|
|
|
|
|
|
|
|
hWndProgress = GetDlgItem(hWnd, IDC_RESTART_PROGRESS);
|
|
|
|
Position = SendMessage(hWndProgress, PBM_GETPOS, 0, 0);
|
|
|
|
if (Position == 300)
|
|
|
|
EndDialog(hWnd, 0);
|
|
|
|
else
|
|
|
|
SendMessage(hWndProgress, PBM_SETPOS, Position + 1, 0);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case IDOK:
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hWnd, 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-01-16 21:33:23 +00:00
|
|
|
|
2004-06-24 09:17:33 +00:00
|
|
|
static VOID
|
|
|
|
CreateTempDir(LPCWSTR VarName)
|
|
|
|
{
|
|
|
|
WCHAR szTempDir[MAX_PATH];
|
|
|
|
WCHAR szBuffer[MAX_PATH];
|
|
|
|
DWORD dwLength;
|
|
|
|
HKEY hKey;
|
|
|
|
|
|
|
|
if (RegOpenKeyExW (HKEY_LOCAL_MACHINE,
|
|
|
|
L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
|
|
|
|
0,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&hKey))
|
|
|
|
{
|
|
|
|
DebugPrint("Error: %lu\n", GetLastError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get temp dir */
|
|
|
|
dwLength = MAX_PATH * sizeof(WCHAR);
|
|
|
|
if (RegQueryValueExW (hKey,
|
|
|
|
VarName,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(LPBYTE)szBuffer,
|
|
|
|
&dwLength))
|
|
|
|
{
|
|
|
|
DebugPrint("Error: %lu\n", GetLastError());
|
|
|
|
RegCloseKey (hKey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Expand it */
|
|
|
|
if (!ExpandEnvironmentStringsW (szBuffer,
|
|
|
|
szTempDir,
|
|
|
|
MAX_PATH))
|
|
|
|
{
|
|
|
|
DebugPrint("Error: %lu\n", GetLastError());
|
|
|
|
RegCloseKey (hKey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create profiles directory */
|
|
|
|
if (!CreateDirectoryW (szTempDir, NULL))
|
|
|
|
{
|
|
|
|
if (GetLastError () != ERROR_ALREADY_EXISTS)
|
|
|
|
{
|
|
|
|
DebugPrint("Error: %lu\n", GetLastError());
|
|
|
|
RegCloseKey (hKey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey (hKey);
|
|
|
|
}
|
|
|
|
|
2004-07-19 01:33:48 +00:00
|
|
|
|
2004-08-03 13:43:00 +00:00
|
|
|
BOOL
|
|
|
|
ProcessSysSetupInf(VOID)
|
|
|
|
{
|
2004-08-28 11:08:50 +00:00
|
|
|
INFCONTEXT InfContext;
|
|
|
|
TCHAR LineBuffer[256];
|
|
|
|
DWORD LineLength;
|
|
|
|
|
|
|
|
if (!SetupFindFirstLine(hSysSetupInf,
|
|
|
|
_T("DeviceInfsToInstall"),
|
|
|
|
NULL,
|
|
|
|
&InfContext))
|
|
|
|
{
|
2004-08-03 13:43:00 +00:00
|
|
|
return FALSE;
|
2004-08-28 11:08:50 +00:00
|
|
|
}
|
2004-08-03 13:43:00 +00:00
|
|
|
|
2004-08-28 11:08:50 +00:00
|
|
|
do
|
2004-08-03 13:43:00 +00:00
|
|
|
{
|
2004-08-28 11:08:50 +00:00
|
|
|
if (!SetupGetStringField(&InfContext,
|
|
|
|
0,
|
|
|
|
LineBuffer,
|
|
|
|
256,
|
|
|
|
&LineLength))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-08-03 13:43:00 +00:00
|
|
|
|
2004-08-28 11:08:50 +00:00
|
|
|
if (!SetupDiInstallClass(NULL, LineBuffer, DI_QUIETINSTALL, NULL))
|
|
|
|
{
|
2004-08-03 13:43:00 +00:00
|
|
|
return FALSE;
|
2004-08-28 11:08:50 +00:00
|
|
|
}
|
2004-08-03 13:43:00 +00:00
|
|
|
}
|
2004-08-28 11:08:50 +00:00
|
|
|
while (SetupFindNextLine(&InfContext, &InfContext));
|
2004-08-03 13:43:00 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2004-07-19 01:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-02 18:12:38 +00:00
|
|
|
DWORD STDCALL
|
|
|
|
InstallReactOS (HINSTANCE hInstance)
|
|
|
|
{
|
2004-01-09 20:05:04 +00:00
|
|
|
# if 0
|
2003-08-07 04:03:25 +00:00
|
|
|
OutputDebugStringA ("InstallReactOS() called\n");
|
2003-05-02 18:12:38 +00:00
|
|
|
|
|
|
|
if (!InitializeSetupActionLog (FALSE))
|
|
|
|
{
|
2003-08-07 04:03:25 +00:00
|
|
|
OutputDebugStringA ("InitializeSetupActionLog() failed\n");
|
2003-05-02 18:12:38 +00:00
|
|
|
}
|
|
|
|
|
2004-01-14 22:15:09 +00:00
|
|
|
LogItem (SYSSETUP_SEVERITY_INFORMATION,
|
2003-05-02 18:12:38 +00:00
|
|
|
L"ReactOS Setup starting");
|
|
|
|
|
2004-01-14 22:15:09 +00:00
|
|
|
LogItem (SYSSETUP_SEVERITY_FATAL_ERROR,
|
2003-05-02 18:12:38 +00:00
|
|
|
L"Buuuuuuaaaah!");
|
|
|
|
|
2004-01-14 22:15:09 +00:00
|
|
|
LogItem (SYSSETUP_SEVERITY_INFORMATION,
|
2003-05-02 18:12:38 +00:00
|
|
|
L"ReactOS Setup finished");
|
|
|
|
|
|
|
|
TerminateSetupActionLog ();
|
2004-01-09 20:05:04 +00:00
|
|
|
#endif
|
2004-01-16 21:33:23 +00:00
|
|
|
#if 0
|
|
|
|
UNICODE_STRING SidString;
|
|
|
|
#endif
|
2004-01-09 20:05:04 +00:00
|
|
|
|
2004-01-16 21:33:23 +00:00
|
|
|
if (!InitializeProfiles ())
|
|
|
|
{
|
2004-01-23 10:35:52 +00:00
|
|
|
DebugPrint ("InitializeProfiles() failed\n");
|
2004-01-16 21:33:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-01-09 20:05:04 +00:00
|
|
|
|
2004-01-23 10:35:52 +00:00
|
|
|
/* Create the semi-random Domain-SID */
|
2004-01-16 21:33:23 +00:00
|
|
|
CreateRandomSid (&DomainSid);
|
|
|
|
if (DomainSid == NULL)
|
2004-01-09 20:05:04 +00:00
|
|
|
{
|
2004-01-23 10:35:52 +00:00
|
|
|
DebugPrint ("Domain-SID creation failed!\n");
|
2004-01-16 21:33:23 +00:00
|
|
|
return 0;
|
2004-01-09 20:05:04 +00:00
|
|
|
}
|
2004-01-16 21:33:23 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
RtlConvertSidToUnicodeString (&SidString, DomainSid, TRUE);
|
|
|
|
DebugPrint ("Domain-SID: %wZ\n", &SidString);
|
|
|
|
RtlFreeUnicodeString (&SidString);
|
|
|
|
#endif
|
|
|
|
|
2004-01-23 10:35:52 +00:00
|
|
|
/* Initialize the Security Account Manager (SAM) */
|
|
|
|
if (!SamInitializeSAM ())
|
2004-01-09 20:05:04 +00:00
|
|
|
{
|
2004-01-23 10:35:52 +00:00
|
|
|
DebugPrint ("SamInitializeSAM() failed!\n");
|
|
|
|
RtlFreeSid (DomainSid);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-01-16 21:33:23 +00:00
|
|
|
|
2004-01-23 10:35:52 +00:00
|
|
|
/* Set the Domain SID (aka Computer SID) */
|
|
|
|
if (!SamSetDomainSid (DomainSid))
|
|
|
|
{
|
|
|
|
DebugPrint ("SamSetDomainSid() failed!\n");
|
2004-01-16 21:33:23 +00:00
|
|
|
RtlFreeSid (DomainSid);
|
|
|
|
return 0;
|
2004-01-09 20:05:04 +00:00
|
|
|
}
|
|
|
|
|
2004-01-23 10:35:52 +00:00
|
|
|
/* Append the Admin-RID */
|
2004-08-28 11:08:50 +00:00
|
|
|
AppendRidToSid(&AdminSid, DomainSid, DOMAIN_USER_RID_ADMIN);
|
2004-01-16 21:33:23 +00:00
|
|
|
|
|
|
|
#if 0
|
2004-01-23 10:35:52 +00:00
|
|
|
RtlConvertSidToUnicodeString (&SidString, DomainSid, TRUE);
|
|
|
|
DebugPrint ("Admin-SID: %wZ\n", &SidString);
|
2004-01-16 21:33:23 +00:00
|
|
|
RtlFreeUnicodeString (&SidString);
|
|
|
|
#endif
|
|
|
|
|
2004-01-23 10:35:52 +00:00
|
|
|
/* Create the Administrator account */
|
2004-08-28 11:08:50 +00:00
|
|
|
if (!SamCreateUser(L"Administrator", L"", AdminSid))
|
|
|
|
{
|
|
|
|
DebugPrint("SamCreateUser() failed!\n");
|
|
|
|
RtlFreeSid(AdminSid);
|
|
|
|
RtlFreeSid(DomainSid);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-01-16 21:33:23 +00:00
|
|
|
|
2004-01-23 10:35:52 +00:00
|
|
|
/* Create the Administrator profile */
|
2004-08-28 11:08:50 +00:00
|
|
|
if (!CreateUserProfileW(AdminSid, L"Administrator"))
|
|
|
|
{
|
|
|
|
DebugPrint("CreateUserProfileW() failed!\n");
|
|
|
|
RtlFreeSid(AdminSid);
|
|
|
|
RtlFreeSid(DomainSid);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-01-16 21:33:23 +00:00
|
|
|
|
2004-08-28 11:08:50 +00:00
|
|
|
RtlFreeSid(AdminSid);
|
|
|
|
RtlFreeSid(DomainSid);
|
2004-01-16 21:33:23 +00:00
|
|
|
|
2004-06-24 09:17:33 +00:00
|
|
|
CreateTempDir(L"TEMP");
|
|
|
|
CreateTempDir(L"TMP");
|
|
|
|
|
2004-08-28 11:08:50 +00:00
|
|
|
hSysSetupInf = SetupOpenInfFileW(L"syssetup.inf",
|
|
|
|
NULL,
|
|
|
|
INF_STYLE_WIN4,
|
|
|
|
NULL);
|
|
|
|
if (hSysSetupInf == INVALID_HANDLE_VALUE)
|
2004-07-19 01:33:48 +00:00
|
|
|
{
|
2004-08-28 11:08:50 +00:00
|
|
|
DebugPrint("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ProcessSysSetupInf())
|
|
|
|
{
|
|
|
|
DebugPrint("ProcessSysSetupInf() failed!\n");
|
|
|
|
return 0;
|
2004-07-19 01:33:48 +00:00
|
|
|
}
|
2004-08-03 13:43:00 +00:00
|
|
|
|
|
|
|
InstallWizard();
|
2003-05-02 18:12:38 +00:00
|
|
|
|
2004-08-28 11:08:50 +00:00
|
|
|
SetupCloseInfFile(hSysSetupInf);
|
|
|
|
|
2004-04-09 18:27:11 +00:00
|
|
|
#ifdef VMWINST
|
2004-08-28 11:08:50 +00:00
|
|
|
RunVMWInstall();
|
2004-04-09 18:27:11 +00:00
|
|
|
#endif
|
2004-04-19 10:54:23 +00:00
|
|
|
|
2004-08-28 11:08:50 +00:00
|
|
|
DialogBox(hDllInstance,
|
|
|
|
MAKEINTRESOURCE(IDD_RESTART),
|
|
|
|
NULL,
|
|
|
|
RestartDlgProc);
|
2004-03-21 14:37:19 +00:00
|
|
|
|
2003-05-02 18:12:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-03 13:43:00 +00:00
|
|
|
|
2003-09-08 09:56:57 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
2004-08-03 13:43:00 +00:00
|
|
|
DWORD STDCALL
|
|
|
|
SetupChangeFontSize(HANDLE hWnd,
|
|
|
|
LPCWSTR lpszFontSize)
|
2003-09-08 09:56:57 +00:00
|
|
|
{
|
2004-08-03 13:43:00 +00:00
|
|
|
return FALSE;
|
2003-09-08 09:56:57 +00:00
|
|
|
}
|