VBoxInstallHelper.cpp revision 0824e642d6a2ba2cde6077003d9c99b0197eab34
/* $Id$ */
/** @file
* VBoxInstallHelper - Various helper routines for Windows host installer.
*/
/*
* Copyright (C) 2008-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifdef VBOX_WITH_NETFLT
# include "VBox/VBoxNetCfg-win.h"
# include "VBox/VBoxDrvCfg-win.h"
#endif /* VBOX_WITH_NETFLT */
#include <windows.h>
#include <wchar.h>
#include <stdio.h>
#include <msi.h>
#include <msiquery.h>
#define _WIN32_DCOM
#include <windows.h>
#include <assert.h>
#include <shellapi.h>
#define INITGUID
#include <guiddef.h>
#include <devguid.h>
#include <objbase.h>
#include <setupapi.h>
#include <shlobj.h>
#include <cfgmgr32.h>
#include "VBoxCommon.h"
#ifndef VBOX_OSE
# include "internal/VBoxSerial.h"
#endif
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifdef DEBUG
#else
# define NonStandardAssert(_expr) do{ }while(0)
#endif
{
return TRUE;
}
{
char szBuffer[1024];
#if 0/*def DEBUG - wrong? What does '%s' expect, wchar or char? */
#endif
}
{
}
{
#ifndef VBOX_OSE
#endif
return ERROR_SUCCESS;
}
{
#ifndef VBOX_OSE
#endif
return ERROR_SUCCESS;
}
{
#ifdef UNICODE
#endif
SetLastError(0);
pwszCmdLine, /* Command line. */
NULL, /* Process handle not inheritable. */
NULL, /* Thread handle not inheritable. */
FALSE, /* Set handle inheritance to FALSE .*/
0, /* No creation flags. */
NULL, /* Use parent's environment block. */
pwszWorkDir, /* Use parent's starting directory. */
&si, /* Pointer to STARTUPINFO structure. */
&pi)) /* Pointer to PROCESS_INFORMATION structure. */
{
rc = GetLastError();
return rc;
}
/* Wait until child process exits. */
{
rc = GetLastError();
}
else
{
{
rc = GetLastError();
}
}
/* Close process and thread handles. */
return rc;
}
{
LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Python\\PythonCore", 0, KEY_READ, &hkPythonCore);
if (rc != ERROR_SUCCESS)
{
return ERROR_SUCCESS;
}
for (int i = 0;; ++i)
{
break;
if (rc != ERROR_SUCCESS)
continue;
if (rc == ERROR_SUCCESS)
}
/* Python path found? */
DWORD dwExitCode = 0;
{
/* Cool, check for installed Win32 extensions. */
if ( (ERROR_SUCCESS == dwRetExec)
&& ( 0 == dwExitCode))
{
/* Did we get the correct error level (=0)? */
}
else
}
if (bFound) /* Is Python and all required stuff installed? */
{
/* Get the VBoxAPI setup string. */
if (wcslen(wszPathTargetDir))
{
/* Set final path. */
/* Install our API module. */
/* Set required environment variables. */
else
{
if ( (ERROR_SUCCESS == dwRetExec)
&& ( 0 == dwExitCode))
{
/* All done! */
bInstalled = TRUE;
}
else
{
if (dwRetExec)
logStringW(hModule, L"InstallPythonAPI: Error while executing installation of VBox API: %ld", dwRetExec);
else
logStringW(hModule, L"InstallPythonAPI: Python reported an error while installing VBox API: %ld", dwExitCode);
}
}
}
else
}
if (!bInstalled)
return ERROR_SUCCESS; /* Do not fail here. */
}
const WCHAR *pwszFileName,
const WCHAR *pwszSection,
{
{
swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding\\", VBOX_VENDOR_SHORT, pwszSection);
else
if (rc == ERROR_SUCCESS)
{
NULL,
if (rc != ERROR_SUCCESS)
}
}
else
return rc;
}
{
SHFILEOPSTRUCT s = {0};
s.fFlags = FOF_SILENT |
int r = SHFileOperation(&s);
if (r != 0)
{
}
else
rc = ERROR_SUCCESS;
return rc;
}
{
SHFILEOPSTRUCTW s = {0};
s.fFlags = FOF_SILENT
int r = SHFileOperationW(&s);
if (r != 0)
{
}
else
rc = ERROR_SUCCESS;
return rc;
}
{
SHFILEOPSTRUCTW s = {0};
s.fFlags = FOF_SILENT
int r = SHFileOperationW(&s);
if (r != 0)
{
}
else
rc = ERROR_SUCCESS;
return rc;
}
{
if (rc == ERROR_SUCCESS)
{
/** @todo Check trailing slash after %s. */
/** @todo r=bird: using swprintf_s for formatting paths without checking for
* overflow not good. You're dodging the buffer overflow issue only to end up
*
* This applies almost to all swprintf_s calls in this file!!
*/
if (rc != ERROR_SUCCESS)
{
/* Check for hidden .custom directory and remove it. */
}
}
return ERROR_SUCCESS; /* Do not fail here. */
}
{
if (rc == ERROR_SUCCESS)
{
if (rc == ERROR_SUCCESS)
{
/** @todo Check for trailing slash after %s. */
if (rc == ERROR_SUCCESS)
{
}
}
}
return ERROR_SUCCESS; /* Do not fail here. */
}
#ifdef VBOX_WITH_NETFLT
/** @todo should use some real VBox app name */
#define VBOX_NETCFG_APP_NAME L"VirtualBox Installer"
#define VBOX_NETCFG_MAX_RETRIES 10
#define NETFLT_PT_INF_REL_PATH L"drivers\\network\\netflt\\VBoxNetFlt.inf"
#define NETFLT_MP_INF_REL_PATH L"drivers\\network\\netflt\\VBoxNetFltM.inf"
{
if (g_hCurrentModule)
}
static VOID netCfgLoggerDisable()
{
if (g_hCurrentModule)
{
}
}
{
if (g_hCurrentModule)
}
{
switch (hr)
{
case S_OK:
break;
case NETCFG_S_REBOOT:
{
if (hr2 != ERROR_SUCCESS)
break;
}
default:
}
return uRet;
}
{
if (hRecord)
{
if (uErr != ERROR_SUCCESS)
{
logStringW(hModule, L"createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = 0x%x", uErr);
}
}
else
return hRecord;
}
{
int MsgResult;
int cRetries = 0;
do
{
if (hr != NETCFG_E_NO_WRITE_LOCK)
{
break;
}
/* hr == NETCFG_E_NO_WRITE_LOCK */
if (!lpszLockedBy)
{
break;
}
/* on vista the 6to4svc.dll periodically maintains the lock for some reason,
* if this is the case, increase the wait period by retrying multiple times
* NOTE: we could alternatively increase the wait timeout,
* however it seems unneeded for most cases, e.g. in case some network connection property
* dialog is opened, it would be better to post a notification to the user as soon as possible
* rather than waiting for a longer period of time before displaying it */
if ( cRetries < VBOX_NETCFG_MAX_RETRIES
{
cRetries++;
logStringW(hModule, L"doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d", cRetries, VBOX_NETCFG_MAX_RETRIES);
}
else
{
if (!hMsg)
{
if (!hMsg)
{
break;
}
}
if (rTmp != ERROR_SUCCESS)
{
break;
}
MsgResult = MsiProcessMessage(hModule, (INSTALLMESSAGE)(INSTALLMESSAGE_USER | MB_RETRYCANCEL), hMsg);
}
if (hMsg)
return uErr;
}
static UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR pwszPtInf, OUT LPWSTR pwszMpInf, DWORD dwSize)
{
if ( uErr == ERROR_SUCCESS
&& dwBuf)
{
}
else if (uErr != ERROR_SUCCESS)
else
{
}
return uErr;
}
#endif /*VBOX_WITH_NETFLT*/
{
#ifdef VBOX_WITH_NETFLT
{
if (uErr == ERROR_SUCCESS)
{
/* Never fail on uninstall. */
}
else
}
{
if (bOldIntMode)
{
/* The prev mode != FALSE, i.e. non-interactive. */
}
}
#endif /* VBOX_WITH_NETFLT */
/* Never fail the install even if we did not succeed. */
return ERROR_SUCCESS;
}
{
#ifdef VBOX_WITH_NETFLT
{
if (uErr == ERROR_SUCCESS)
{
if (uErr == ERROR_SUCCESS)
{
}
else
}
else
}
{
if (bOldIntMode)
{
/* The prev mode != FALSE, i.e. non-interactive. */
}
}
#endif /* VBOX_WITH_NETFLT */
/* Never fail the install even if we did not succeed. */
return ERROR_SUCCESS;
}
#if 0
static BOOL RenameHostOnlyConnectionsCallback(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext)
{
SPDRP_FRIENDLYNAME , /* IN DWORD Property,*/
NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/
sizeof(DevName), /* IN DWORD PropertyBufferSize,*/
NULL /*OUT PDWORD RequiredSize OPTIONAL*/
))
{
DICS_FLAG_GLOBAL, /* IN DWORD Scope,*/
0, /*IN DWORD HwProfile, */
DIREG_DRV, /* IN DWORD KeyType, */
KEY_READ /*IN REGSAM samDesired*/
);
if (hKey != INVALID_HANDLE_VALUE)
{
L"NetCfgInstanceId", /*__in_opt LPCTSTR lpValueName,*/
NULL, /*__reserved LPDWORD lpReserved,*/
NULL, /*__out_opt LPDWORD lpType,*/
&cbGuid /*guid__inout_opt LPDWORD lpcbData*/
);
if (winEr == ERROR_SUCCESS)
{
{
}
}
}
}
else
{
}
return TRUE;
}
#endif
{
#ifdef VBOX_WITH_NETFLT
bool bSetStaticIp = true;
{
logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinRemoveAllNetDevicesOfId failed, error = 0x%x", hr);
bSetStaticIp = false;
}
bool bIsFile = false;
if (uErr == ERROR_SUCCESS)
{
if (cchMpInf)
{
{
}
bIsFile = true;
}
else
}
else
logStringW(hModule, L"CreateHostOnlyInterface: Failed to get NetAdpDir property, error = 0x%x", uErr);
/* Make sure the inf file is installed. */
{
}
{
logStringW(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinCreateHostOnlyNetworkInterface");
logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface returns 0x%x", hr);
{
logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig returns 0x%x", hr);
logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = 0x%x", hr);
}
else
logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = 0x%x", hr);
}
/* Restore original setup mode. */
#endif /* VBOX_WITH_NETFLT */
/* Never fail the install even if we did not succeed. */
return ERROR_SUCCESS;
}
{
#ifdef VBOX_WITH_NETFLT
{
hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, NETADP_ID, L"Net", 0/* could be SUOI_FORCEDELETE */);
{
logStringW(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove infs\n");
}
}
else
/* Restore original setup mode. */
#endif /* VBOX_WITH_NETFLT */
/* Never fail the install even if we did not succeed. */
return ERROR_SUCCESS;
}
{
bool bIsTapDevice = false;
L"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}",
if (lStatus != ERROR_SUCCESS)
return false;
int i = 0;
for (;;)
{
if (lStatus != ERROR_SUCCESS)
break;
if (lStatus == ERROR_SUCCESS)
{
dwLen = sizeof(wszNetCfgInstanceId);
lStatus = RegQueryValueExW(hNetCardGUID, L"NetCfgInstanceId", NULL, &dwKeyType, (LPBYTE)wszNetCfgInstanceId, &dwLen);
if ( lStatus == ERROR_SUCCESS
{
wszNetProductName[0] = 0;
dwLen = sizeof(wszNetProductName);
lStatus = RegQueryValueExW(hNetCardGUID, L"ProductName", NULL, &dwKeyType, (LPBYTE)wszNetProductName, &dwLen);
wszNetProviderName[0] = 0;
dwLen = sizeof(wszNetProviderName);
lStatus = RegQueryValueExW(hNetCardGUID, L"ProviderName", NULL, &dwKeyType, (LPBYTE)wszNetProviderName, &dwLen);
)
)
{
bIsTapDevice = true;
break;
}
}
}
++i;
}
return bIsTapDevice;
}
#define SetErrBreak(strAndArgs) \
if (1) { \
rc = 0; \
break; \
} else do {} while (0)
{
int rc = 1;
do
{
/* We have to find the device instance ID through a registry search */
HKEY hkeyNetwork = 0;
HKEY hkeyConnection = 0;
do /* break-loop */
{
L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s",
pwszGUID);
SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]", wszRegLocation));
SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]", wszRegLocation));
SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]", wszRegLocation));
}
while (0);
if (hkeyConnection)
if (hkeyNetwork)
/*
* Now we are going to enumerate all network devices and
* wait until we encounter the right device instance ID
*/
do
{
/* initialize the structure size */
/* copy the net class GUID */
/* return a device info set contains all installed devices of the Net class */
if (hDeviceInfo == INVALID_HANDLE_VALUE)
{
SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
}
/* enumerate the driver info list */
while (TRUE)
{
if (!fResult)
{
if (GetLastError() == ERROR_NO_MORE_ITEMS)
break;
else
{
index++;
continue;
}
}
/* try to get the hardware ID registry property */
NULL,
NULL,
0,
&size);
if (!fResult)
{
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
index++;
continue;
}
if (pwszDeviceHwid)
{
NULL,
size,
NULL);
if (!fResult)
{
index++;
continue;
}
}
}
else
{
/* something is wrong. This shouldn't have worked with a NULL buffer */
index++;
continue;
}
for (WCHAR *t = pwszDeviceHwid;
t += wcslen(t) + 1)
{
if (!_wcsicmp(L"vboxtap", t))
{
/* get the device instance ID */
{
/* compare to what we determined before */
{
fFoundDevice = TRUE;
break;
}
}
}
}
if (pwszDeviceHwid)
{
}
if (fFoundDevice)
break;
index++;
}
if (fFoundDevice)
{
if (!fResult)
{
logStringW(hModule, L"VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!", GetLastError());
SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
}
if (!fResult)
{
logStringW(hModule, L"VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!", GetLastError());
SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
}
}
else
SetErrBreak(L"VBox HostInterfaces: Host interface network device not found!");
}
while (0);
/* clean up the device info set */
if (hDeviceInfo != INVALID_HANDLE_VALUE)
}
while (0);
return rc;
}
{
static const WCHAR *s_wszNetworkKey = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
if (lStatus == ERROR_SUCCESS)
{
for (int i = 0; ; ++i)
{
if (lStatus != ERROR_SUCCESS)
{
switch (lStatus)
{
case ERROR_NO_MORE_ITEMS:
break;
default:
break;
}
break;
}
if (isTAPDevice(wszNetworkGUID))
{
}
}
}
return ERROR_SUCCESS;
}