1 | /* $Id: VBoxInstallHelper.cpp 57358 2015-08-14 15:16:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxInstallHelper - Various helper routines for Windows host installer.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2015 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #ifdef VBOX_WITH_NETFLT
|
---|
23 | # include "VBox/VBoxNetCfg-win.h"
|
---|
24 | # include "VBox/VBoxDrvCfg-win.h"
|
---|
25 | #endif /* VBOX_WITH_NETFLT */
|
---|
26 |
|
---|
27 | #include <VBox/version.h>
|
---|
28 |
|
---|
29 | #include <windows.h>
|
---|
30 | #include <wchar.h>
|
---|
31 | #include <stdio.h>
|
---|
32 |
|
---|
33 | #include <msi.h>
|
---|
34 | #include <msiquery.h>
|
---|
35 |
|
---|
36 | #define _WIN32_DCOM
|
---|
37 | #include <windows.h>
|
---|
38 | #include <assert.h>
|
---|
39 | #include <shellapi.h>
|
---|
40 | #define INITGUID
|
---|
41 | #include <guiddef.h>
|
---|
42 | #include <devguid.h>
|
---|
43 | #include <objbase.h>
|
---|
44 | #include <setupapi.h>
|
---|
45 | #include <shlobj.h>
|
---|
46 | #include <cfgmgr32.h>
|
---|
47 |
|
---|
48 | #include "VBoxCommon.h"
|
---|
49 |
|
---|
50 | #ifndef VBOX_OSE
|
---|
51 | # include "internal/VBoxSerial.h"
|
---|
52 | #endif
|
---|
53 |
|
---|
54 |
|
---|
55 | /*********************************************************************************************************************************
|
---|
56 | * Header Files *
|
---|
57 | *********************************************************************************************************************************/
|
---|
58 | #ifdef DEBUG
|
---|
59 | # define NonStandardAssert(_expr) assert(_expr)
|
---|
60 | #else
|
---|
61 | # define NonStandardAssert(_expr) do{ }while(0)
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | #define MY_WTEXT_HLP(a_str) L##a_str
|
---|
65 | #define MY_WTEXT(a_str) MY_WTEXT_HLP(a_str)
|
---|
66 |
|
---|
67 |
|
---|
68 | BOOL APIENTRY DllMain(HANDLE hModule,
|
---|
69 | DWORD ul_reason_for_call,
|
---|
70 | LPVOID lpReserved)
|
---|
71 | {
|
---|
72 | return TRUE;
|
---|
73 | }
|
---|
74 |
|
---|
75 | static void logString(MSIHANDLE hInstall, LPCSTR szString, ...)
|
---|
76 | {
|
---|
77 | PMSIHANDLE newHandle = MsiCreateRecord(2);
|
---|
78 |
|
---|
79 | char szBuffer[1024];
|
---|
80 | va_list va;
|
---|
81 | va_start(va, szString);
|
---|
82 | _vsnprintf(szBuffer, sizeof(szBuffer), szString, va);
|
---|
83 | va_end(va);
|
---|
84 |
|
---|
85 | MsiRecordSetStringA(newHandle, 0, szBuffer);
|
---|
86 | MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle);
|
---|
87 | MsiCloseHandle(newHandle);
|
---|
88 |
|
---|
89 | #if 0/*def DEBUG - wrong? What does '%s' expect, wchar or char? */
|
---|
90 | _tprintf(_T("Debug: %s\n"), szBuffer);
|
---|
91 | #endif
|
---|
92 | }
|
---|
93 |
|
---|
94 | static void logStringW(MSIHANDLE hInstall, LPCWSTR pwszString, ...)
|
---|
95 | {
|
---|
96 | PMSIHANDLE newHandle = MsiCreateRecord(2);
|
---|
97 |
|
---|
98 | WCHAR szBuffer[1024];
|
---|
99 | va_list va;
|
---|
100 | va_start(va, pwszString);
|
---|
101 | _vsnwprintf(szBuffer, RT_ELEMENTS(szBuffer), pwszString, va);
|
---|
102 | va_end(va);
|
---|
103 |
|
---|
104 | MsiRecordSetStringW(newHandle, 0, szBuffer);
|
---|
105 | MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), newHandle);
|
---|
106 | MsiCloseHandle(newHandle);
|
---|
107 | }
|
---|
108 |
|
---|
109 | UINT __stdcall IsSerialCheckNeeded(MSIHANDLE hModule)
|
---|
110 | {
|
---|
111 | #ifndef VBOX_OSE
|
---|
112 | /*BOOL bRet =*/ serialCheckNeeded(hModule);
|
---|
113 | #endif
|
---|
114 | return ERROR_SUCCESS;
|
---|
115 | }
|
---|
116 |
|
---|
117 | UINT __stdcall CheckSerial(MSIHANDLE hModule)
|
---|
118 | {
|
---|
119 | #ifndef VBOX_OSE
|
---|
120 | /*BOOL bRet =*/ serialIsValid(hModule);
|
---|
121 | #endif
|
---|
122 | return ERROR_SUCCESS;
|
---|
123 | }
|
---|
124 |
|
---|
125 | DWORD Exec(MSIHANDLE hModule,
|
---|
126 | const WCHAR *pwszAppName, WCHAR *pwszCmdLine, const WCHAR *pwszWorkDir,
|
---|
127 | DWORD *pdwExitCode)
|
---|
128 | {
|
---|
129 | STARTUPINFOW si;
|
---|
130 | PROCESS_INFORMATION pi;
|
---|
131 | DWORD rc = ERROR_SUCCESS;
|
---|
132 |
|
---|
133 | ZeroMemory(&si, sizeof(si));
|
---|
134 | si.dwFlags = STARTF_USESHOWWINDOW;
|
---|
135 | #ifdef UNICODE
|
---|
136 | si.dwFlags |= CREATE_UNICODE_ENVIRONMENT;
|
---|
137 | #endif
|
---|
138 | si.wShowWindow = SW_HIDE; /* For debugging: SW_SHOW; */
|
---|
139 | si.cb = sizeof(si);
|
---|
140 | ZeroMemory(&pi, sizeof(pi));
|
---|
141 |
|
---|
142 | logStringW(hModule, L"Executing command line: %s %s (Working Dir: %s)",
|
---|
143 | pwszAppName, pwszCmdLine, pwszWorkDir == NULL ? L"Current" : pwszWorkDir);
|
---|
144 |
|
---|
145 | SetLastError(0);
|
---|
146 | if (!CreateProcessW(pwszAppName, /* Module name. */
|
---|
147 | pwszCmdLine, /* Command line. */
|
---|
148 | NULL, /* Process handle not inheritable. */
|
---|
149 | NULL, /* Thread handle not inheritable. */
|
---|
150 | FALSE, /* Set handle inheritance to FALSE .*/
|
---|
151 | 0, /* No creation flags. */
|
---|
152 | NULL, /* Use parent's environment block. */
|
---|
153 | pwszWorkDir, /* Use parent's starting directory. */
|
---|
154 | &si, /* Pointer to STARTUPINFO structure. */
|
---|
155 | &pi)) /* Pointer to PROCESS_INFORMATION structure. */
|
---|
156 | {
|
---|
157 | rc = GetLastError();
|
---|
158 | logStringW(hModule, L"Executing command line: CreateProcess() failed! Error: %ld", rc);
|
---|
159 | return rc;
|
---|
160 | }
|
---|
161 |
|
---|
162 | /* Wait until child process exits. */
|
---|
163 | if (WAIT_FAILED == WaitForSingleObject(pi.hProcess, 30 * 1000 /* Wait 30 secs max. */))
|
---|
164 | {
|
---|
165 | rc = GetLastError();
|
---|
166 | logStringW(hModule, L"Executing command line: WaitForSingleObject() failed! Error: %u", rc);
|
---|
167 | }
|
---|
168 | else
|
---|
169 | {
|
---|
170 | if (!GetExitCodeProcess(pi.hProcess, pdwExitCode))
|
---|
171 | {
|
---|
172 | rc = GetLastError();
|
---|
173 | logStringW(hModule, L"Executing command line: GetExitCodeProcess() failed! Error: %u", rc);
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | /* Close process and thread handles. */
|
---|
178 | CloseHandle(pi.hProcess);
|
---|
179 | CloseHandle(pi.hThread);
|
---|
180 |
|
---|
181 | logStringW(hModule, L"Executing command returned: %u (exit code %u)", rc, *pdwExitCode);
|
---|
182 | return rc;
|
---|
183 | }
|
---|
184 |
|
---|
185 | UINT __stdcall InstallPythonAPI(MSIHANDLE hModule)
|
---|
186 | {
|
---|
187 | logStringW(hModule, L"InstallPythonAPI: Checking for installed Python environment ...");
|
---|
188 |
|
---|
189 | HKEY hkPythonCore = NULL;
|
---|
190 | BOOL bFound = FALSE;
|
---|
191 | LONG rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Python\\PythonCore", 0, KEY_READ, &hkPythonCore);
|
---|
192 | if (rc != ERROR_SUCCESS)
|
---|
193 | {
|
---|
194 | logStringW(hModule, L"InstallPythonAPI: Python seems not to be installed.");
|
---|
195 | return ERROR_SUCCESS;
|
---|
196 | }
|
---|
197 |
|
---|
198 | WCHAR wszPath[MAX_PATH] = { 0 };
|
---|
199 | WCHAR wszVal[MAX_PATH] = { 0 };
|
---|
200 |
|
---|
201 | for (int i = 0;; ++i)
|
---|
202 | {
|
---|
203 | WCHAR wszRoot[MAX_PATH] = { 0 };
|
---|
204 | DWORD dwLen = sizeof(wszPath);
|
---|
205 | DWORD dwKeyType = REG_SZ;
|
---|
206 |
|
---|
207 | rc = RegEnumKeyExW(hkPythonCore, i, wszRoot, &dwLen, NULL, NULL, NULL, NULL);
|
---|
208 | if (rc != ERROR_SUCCESS || dwLen <= 0)
|
---|
209 | break;
|
---|
210 |
|
---|
211 | swprintf_s(wszPath, RT_ELEMENTS(wszPath), L"%s\\InstallPath", wszRoot);
|
---|
212 | dwLen = sizeof(wszVal);
|
---|
213 |
|
---|
214 | HKEY hkPythonInstPath = NULL;
|
---|
215 | rc = RegOpenKeyExW(hkPythonCore, wszPath, 0, KEY_READ, &hkPythonInstPath);
|
---|
216 | if (rc != ERROR_SUCCESS)
|
---|
217 | continue;
|
---|
218 |
|
---|
219 | rc = RegQueryValueExW(hkPythonInstPath, L"", NULL, &dwKeyType, (LPBYTE)wszVal, &dwLen);
|
---|
220 | if (rc == ERROR_SUCCESS)
|
---|
221 | logStringW(hModule, L"InstallPythonAPI: Path \"%s\" detected.", wszVal);
|
---|
222 |
|
---|
223 | RegCloseKey(hkPythonInstPath);
|
---|
224 | }
|
---|
225 | RegCloseKey(hkPythonCore);
|
---|
226 |
|
---|
227 | /* Python path found? */
|
---|
228 | WCHAR wszExec[MAX_PATH] = { 0 };
|
---|
229 | WCHAR wszCmdLine[MAX_PATH] = { 0 };
|
---|
230 | DWORD dwExitCode = 0;
|
---|
231 | if (wcslen(wszVal) > 0)
|
---|
232 | {
|
---|
233 | /* Cool, check for installed Win32 extensions. */
|
---|
234 | logStringW(hModule, L"InstallPythonAPI: Python installed. Checking for Win32 extensions ...");
|
---|
235 | swprintf_s(wszExec, RT_ELEMENTS(wszExec), L"%s\\python.exe", wszVal);
|
---|
236 | swprintf_s(wszCmdLine, RT_ELEMENTS(wszCmdLine), L"%s\\python.exe -c \"import win32api\"", wszVal);
|
---|
237 |
|
---|
238 | DWORD dwRetExec = Exec(hModule, wszExec, wszCmdLine, NULL, &dwExitCode);
|
---|
239 | if ( (ERROR_SUCCESS == dwRetExec)
|
---|
240 | && ( 0 == dwExitCode))
|
---|
241 | {
|
---|
242 | /* Did we get the correct error level (=0)? */
|
---|
243 | logStringW(hModule, L"InstallPythonAPI: Win32 extensions installed.");
|
---|
244 | bFound = TRUE;
|
---|
245 | }
|
---|
246 | else
|
---|
247 | logStringW(hModule, L"InstallPythonAPI: Win32 extensions not found.");
|
---|
248 | }
|
---|
249 |
|
---|
250 | BOOL bInstalled = FALSE;
|
---|
251 | if (bFound) /* Is Python and all required stuff installed? */
|
---|
252 | {
|
---|
253 | /* Get the VBoxAPI setup string. */
|
---|
254 | WCHAR wszPathTargetDir[MAX_PATH] = {0};
|
---|
255 | VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir));
|
---|
256 | if (wcslen(wszPathTargetDir))
|
---|
257 | {
|
---|
258 | /* Set final path. */
|
---|
259 | swprintf_s(wszPath, RT_ELEMENTS(wszPath), L"%s", wszPathTargetDir);
|
---|
260 |
|
---|
261 | /* Install our API module. */
|
---|
262 | swprintf_s(wszCmdLine, RT_ELEMENTS(wszCmdLine), L"%s\\python.exe vboxapisetup.py install", wszVal);
|
---|
263 |
|
---|
264 | /* Set required environment variables. */
|
---|
265 | if (!SetEnvironmentVariableW(L"VBOX_INSTALL_PATH", wszPathTargetDir))
|
---|
266 | logStringW(hModule, L"InstallPythonAPI: Could set environment variable VBOX_INSTALL_PATH!");
|
---|
267 | else
|
---|
268 | {
|
---|
269 | DWORD dwRetExec = Exec(hModule, wszExec, wszCmdLine, wszPath, &dwExitCode);
|
---|
270 | if ( (ERROR_SUCCESS == dwRetExec)
|
---|
271 | && ( 0 == dwExitCode))
|
---|
272 | {
|
---|
273 | /* All done! */
|
---|
274 | logStringW(hModule, L"InstallPythonAPI: VBoxAPI for Python successfully installed.");
|
---|
275 | bInstalled = TRUE;
|
---|
276 | }
|
---|
277 | else
|
---|
278 | {
|
---|
279 | if (dwRetExec)
|
---|
280 | logStringW(hModule, L"InstallPythonAPI: Error while executing installation of VBox API: %ld", dwRetExec);
|
---|
281 | else
|
---|
282 | logStringW(hModule, L"InstallPythonAPI: Python reported an error while installing VBox API: %ld", dwExitCode);
|
---|
283 | }
|
---|
284 | }
|
---|
285 | }
|
---|
286 | else
|
---|
287 | logStringW(hModule, L"InstallPythonAPI: Unable to retrieve VBox installation path!");
|
---|
288 | }
|
---|
289 |
|
---|
290 | VBoxSetProperty(hModule, L"VBOX_PYTHON_IS_INSTALLED", bInstalled ? L"1" : L"0");
|
---|
291 |
|
---|
292 | if (!bInstalled)
|
---|
293 | logStringW(hModule, L"InstallPythonAPI: VBox API not installed.");
|
---|
294 | return ERROR_SUCCESS; /* Do not fail here. */
|
---|
295 | }
|
---|
296 |
|
---|
297 | static LONG installBrandingValue(MSIHANDLE hModule,
|
---|
298 | const WCHAR *pwszFileName,
|
---|
299 | const WCHAR *pwszSection,
|
---|
300 | const WCHAR *pwszValue)
|
---|
301 | {
|
---|
302 | LONG rc;
|
---|
303 | WCHAR wszValue[_MAX_PATH];
|
---|
304 | if (GetPrivateProfileStringW(pwszSection, pwszValue, NULL,
|
---|
305 | wszValue, sizeof(wszValue), pwszFileName) > 0)
|
---|
306 | {
|
---|
307 | HKEY hkBranding;
|
---|
308 | WCHAR wszKey[_MAX_PATH];
|
---|
309 |
|
---|
310 | if (wcsicmp(L"General", pwszSection) != 0)
|
---|
311 | swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding\\%s", VBOX_VENDOR_SHORT, pwszSection);
|
---|
312 | else
|
---|
313 | swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT);
|
---|
314 |
|
---|
315 | rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszKey, 0, KEY_WRITE, &hkBranding);
|
---|
316 | if (rc == ERROR_SUCCESS)
|
---|
317 | {
|
---|
318 | rc = RegSetValueExW(hkBranding,
|
---|
319 | pwszValue,
|
---|
320 | NULL,
|
---|
321 | REG_SZ,
|
---|
322 | (BYTE *)wszValue,
|
---|
323 | (DWORD)wcslen(wszValue));
|
---|
324 | if (rc != ERROR_SUCCESS)
|
---|
325 | logStringW(hModule, L"InstallBranding: Could not write value %s! Error %ld", pwszValue, rc);
|
---|
326 | RegCloseKey (hkBranding);
|
---|
327 | }
|
---|
328 | }
|
---|
329 | else
|
---|
330 | rc = ERROR_NOT_FOUND;
|
---|
331 | return rc;
|
---|
332 | }
|
---|
333 |
|
---|
334 | UINT CopyDir(MSIHANDLE hModule, const WCHAR *pwszDestDir, const WCHAR *pwszSourceDir)
|
---|
335 | {
|
---|
336 | UINT rc;
|
---|
337 | WCHAR wszDest[_MAX_PATH + 1];
|
---|
338 | WCHAR wszSource[_MAX_PATH + 1];
|
---|
339 |
|
---|
340 | swprintf_s(wszDest, RT_ELEMENTS(wszDest), L"%s%c", pwszDestDir, L'\0');
|
---|
341 | swprintf_s(wszSource, RT_ELEMENTS(wszSource), L"%s%c", pwszSourceDir, L'\0');
|
---|
342 |
|
---|
343 | SHFILEOPSTRUCTW s = {0};
|
---|
344 | s.hwnd = NULL;
|
---|
345 | s.wFunc = FO_COPY;
|
---|
346 | s.pTo = wszDest;
|
---|
347 | s.pFrom = wszSource;
|
---|
348 | s.fFlags = FOF_SILENT |
|
---|
349 | FOF_NOCONFIRMATION |
|
---|
350 | FOF_NOCONFIRMMKDIR |
|
---|
351 | FOF_NOERRORUI;
|
---|
352 |
|
---|
353 | logStringW(hModule, L"CopyDir: DestDir=%s, SourceDir=%s", wszDest, wszSource);
|
---|
354 | int r = SHFileOperationW(&s);
|
---|
355 | if (r != 0)
|
---|
356 | {
|
---|
357 | logStringW(hModule, L"CopyDir: Copy operation returned status 0x%x", r);
|
---|
358 | rc = ERROR_GEN_FAILURE;
|
---|
359 | }
|
---|
360 | else
|
---|
361 | rc = ERROR_SUCCESS;
|
---|
362 | return rc;
|
---|
363 | }
|
---|
364 |
|
---|
365 | UINT RemoveDir(MSIHANDLE hModule, const WCHAR *pwszDestDir)
|
---|
366 | {
|
---|
367 | UINT rc;
|
---|
368 | WCHAR wszDest[_MAX_PATH + 1];
|
---|
369 |
|
---|
370 | swprintf_s(wszDest, RT_ELEMENTS(wszDest), L"%s%c", pwszDestDir, L'\0');
|
---|
371 |
|
---|
372 | SHFILEOPSTRUCTW s = {0};
|
---|
373 | s.hwnd = NULL;
|
---|
374 | s.wFunc = FO_DELETE;
|
---|
375 | s.pFrom = wszDest;
|
---|
376 | s.fFlags = FOF_SILENT
|
---|
377 | | FOF_NOCONFIRMATION
|
---|
378 | | FOF_NOCONFIRMMKDIR
|
---|
379 | | FOF_NOERRORUI;
|
---|
380 |
|
---|
381 | logStringW(hModule, L"RemoveDir: DestDir=%s", wszDest);
|
---|
382 | int r = SHFileOperationW(&s);
|
---|
383 | if (r != 0)
|
---|
384 | {
|
---|
385 | logStringW(hModule, L"RemoveDir: Remove operation returned status 0x%x", r);
|
---|
386 | rc = ERROR_GEN_FAILURE;
|
---|
387 | }
|
---|
388 | else
|
---|
389 | rc = ERROR_SUCCESS;
|
---|
390 | return rc;
|
---|
391 | }
|
---|
392 |
|
---|
393 | UINT RenameDir(MSIHANDLE hModule, const WCHAR *pwszDestDir, const WCHAR *pwszSourceDir)
|
---|
394 | {
|
---|
395 | UINT rc;
|
---|
396 | WCHAR wszDest[_MAX_PATH + 1];
|
---|
397 | WCHAR wszSource[_MAX_PATH + 1];
|
---|
398 |
|
---|
399 | swprintf_s(wszDest, RT_ELEMENTS(wszDest), L"%s%c", pwszDestDir, L'\0');
|
---|
400 | swprintf_s(wszSource, RT_ELEMENTS(wszSource), L"%s%c", pwszSourceDir, L'\0');
|
---|
401 |
|
---|
402 | SHFILEOPSTRUCTW s = {0};
|
---|
403 | s.hwnd = NULL;
|
---|
404 | s.wFunc = FO_RENAME;
|
---|
405 | s.pTo = wszDest;
|
---|
406 | s.pFrom = wszSource;
|
---|
407 | s.fFlags = FOF_SILENT
|
---|
408 | | FOF_NOCONFIRMATION
|
---|
409 | | FOF_NOCONFIRMMKDIR
|
---|
410 | | FOF_NOERRORUI;
|
---|
411 |
|
---|
412 | logStringW(hModule, L"RenameDir: DestDir=%s, SourceDir=%s", wszDest, wszSource);
|
---|
413 | int r = SHFileOperationW(&s);
|
---|
414 | if (r != 0)
|
---|
415 | {
|
---|
416 | logStringW(hModule, L"RenameDir: Rename operation returned status 0x%x", r);
|
---|
417 | rc = ERROR_GEN_FAILURE;
|
---|
418 | }
|
---|
419 | else
|
---|
420 | rc = ERROR_SUCCESS;
|
---|
421 | return rc;
|
---|
422 | }
|
---|
423 |
|
---|
424 | UINT __stdcall UninstallBranding(MSIHANDLE hModule)
|
---|
425 | {
|
---|
426 | UINT rc;
|
---|
427 | logStringW(hModule, L"UninstallBranding: Handling branding file ...");
|
---|
428 |
|
---|
429 | WCHAR wszPathTargetDir[_MAX_PATH];
|
---|
430 | WCHAR wszPathDest[_MAX_PATH];
|
---|
431 |
|
---|
432 | rc = VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir));
|
---|
433 | if (rc == ERROR_SUCCESS)
|
---|
434 | {
|
---|
435 | /** @todo Check trailing slash after %s. */
|
---|
436 | /** @todo r=bird: using swprintf_s for formatting paths without checking for
|
---|
437 | * overflow not good. You're dodging the buffer overflow issue only to end up
|
---|
438 | * with incorrect behavior! (Truncated file/dir names)
|
---|
439 | *
|
---|
440 | * This applies almost to all swprintf_s calls in this file!!
|
---|
441 | */
|
---|
442 | swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%scustom", wszPathTargetDir);
|
---|
443 | rc = RemoveDir(hModule, wszPathDest);
|
---|
444 | if (rc != ERROR_SUCCESS)
|
---|
445 | {
|
---|
446 | /* Check for hidden .custom directory and remove it. */
|
---|
447 | swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%s.custom", wszPathTargetDir);
|
---|
448 | rc = RemoveDir(hModule, wszPathDest);
|
---|
449 | }
|
---|
450 | }
|
---|
451 |
|
---|
452 | logStringW(hModule, L"UninstallBranding: Handling done. (rc=%u (ignored))", rc);
|
---|
453 | return ERROR_SUCCESS; /* Do not fail here. */
|
---|
454 | }
|
---|
455 |
|
---|
456 | UINT __stdcall InstallBranding(MSIHANDLE hModule)
|
---|
457 | {
|
---|
458 | UINT rc;
|
---|
459 | logStringW(hModule, L"InstallBranding: Handling branding file ...");
|
---|
460 |
|
---|
461 | WCHAR wszPathMSI[_MAX_PATH];
|
---|
462 | rc = VBoxGetProperty(hModule, L"SOURCEDIR", wszPathMSI, sizeof(wszPathMSI));
|
---|
463 | if (rc == ERROR_SUCCESS)
|
---|
464 | {
|
---|
465 | WCHAR wszPathTargetDir[_MAX_PATH];
|
---|
466 | rc = VBoxGetProperty(hModule, L"CustomActionData", wszPathTargetDir, sizeof(wszPathTargetDir));
|
---|
467 | if (rc == ERROR_SUCCESS)
|
---|
468 | {
|
---|
469 | /** @todo Check for trailing slash after %s. */
|
---|
470 | WCHAR wszPathDest[_MAX_PATH];
|
---|
471 | swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%s", wszPathTargetDir);
|
---|
472 |
|
---|
473 | WCHAR wszPathSource[_MAX_PATH];
|
---|
474 | swprintf_s(wszPathSource, RT_ELEMENTS(wszPathSource), L"%s.custom", wszPathMSI);
|
---|
475 | rc = CopyDir(hModule, wszPathDest, wszPathSource);
|
---|
476 | if (rc == ERROR_SUCCESS)
|
---|
477 | {
|
---|
478 | swprintf_s(wszPathDest, RT_ELEMENTS(wszPathDest), L"%scustom", wszPathTargetDir);
|
---|
479 | swprintf_s(wszPathSource, RT_ELEMENTS(wszPathSource), L"%s.custom", wszPathTargetDir);
|
---|
480 | rc = RenameDir(hModule, wszPathDest, wszPathSource);
|
---|
481 | }
|
---|
482 | }
|
---|
483 | }
|
---|
484 |
|
---|
485 | logStringW(hModule, L"InstallBranding: Handling done. (rc=%u (ignored))", rc);
|
---|
486 | return ERROR_SUCCESS; /* Do not fail here. */
|
---|
487 | }
|
---|
488 |
|
---|
489 | #ifdef VBOX_WITH_NETFLT
|
---|
490 |
|
---|
491 | /** @todo should use some real VBox app name */
|
---|
492 | #define VBOX_NETCFG_APP_NAME L"VirtualBox Installer"
|
---|
493 | #define VBOX_NETCFG_MAX_RETRIES 10
|
---|
494 | #define NETFLT_PT_INF_REL_PATH L"VBoxNetFlt.inf"
|
---|
495 | #define NETFLT_MP_INF_REL_PATH L"VBoxNetFltM.inf"
|
---|
496 | #define NETFLT_ID L"sun_VBoxNetFlt" /** @todo Needs to be changed (?). */
|
---|
497 | #define NETADP_ID L"sun_VBoxNetAdp" /** @todo Needs to be changed (?). */
|
---|
498 |
|
---|
499 | #define NETLWF_INF_NAME L"VBoxNetLwf.inf"
|
---|
500 |
|
---|
501 | static MSIHANDLE g_hCurrentModule = NULL;
|
---|
502 |
|
---|
503 | static VOID vboxDrvLoggerCallback(VBOXDRVCFG_LOG_SEVERITY enmSeverity, char * msg, void * pvContext)
|
---|
504 | {
|
---|
505 | switch (enmSeverity)
|
---|
506 | {
|
---|
507 | case VBOXDRVCFG_LOG_SEVERITY_FLOW:
|
---|
508 | case VBOXDRVCFG_LOG_SEVERITY_REGULAR:
|
---|
509 | break;
|
---|
510 | case VBOXDRVCFG_LOG_SEVERITY_REL:
|
---|
511 | if (g_hCurrentModule)
|
---|
512 | logString(g_hCurrentModule, (LPCSTR)msg);
|
---|
513 | break;
|
---|
514 | default:
|
---|
515 | break;
|
---|
516 | }
|
---|
517 | }
|
---|
518 |
|
---|
519 | static VOID netCfgLoggerCallback(LPCSTR szString)
|
---|
520 | {
|
---|
521 | if (g_hCurrentModule)
|
---|
522 | logString(g_hCurrentModule, szString);
|
---|
523 | }
|
---|
524 |
|
---|
525 | static VOID netCfgLoggerDisable()
|
---|
526 | {
|
---|
527 | if (g_hCurrentModule)
|
---|
528 | {
|
---|
529 | VBoxNetCfgWinSetLogging((LOG_ROUTINE)NULL);
|
---|
530 | g_hCurrentModule = NULL;
|
---|
531 | }
|
---|
532 | }
|
---|
533 |
|
---|
534 | static VOID netCfgLoggerEnable(MSIHANDLE hModule)
|
---|
535 | {
|
---|
536 | NonStandardAssert(hModule);
|
---|
537 |
|
---|
538 | if (g_hCurrentModule)
|
---|
539 | netCfgLoggerDisable();
|
---|
540 |
|
---|
541 | g_hCurrentModule = hModule;
|
---|
542 |
|
---|
543 | VBoxNetCfgWinSetLogging((LOG_ROUTINE)netCfgLoggerCallback);
|
---|
544 | /* uncomment next line if you want to add logging information from VBoxDrvCfg.cpp */
|
---|
545 | // VBoxDrvCfgLoggerSet(vboxDrvLoggerCallback, NULL);
|
---|
546 | }
|
---|
547 |
|
---|
548 | static UINT errorConvertFromHResult(MSIHANDLE hModule, HRESULT hr)
|
---|
549 | {
|
---|
550 | UINT uRet;
|
---|
551 | switch (hr)
|
---|
552 | {
|
---|
553 | case S_OK:
|
---|
554 | uRet = ERROR_SUCCESS;
|
---|
555 | break;
|
---|
556 |
|
---|
557 | case NETCFG_S_REBOOT:
|
---|
558 | {
|
---|
559 | logStringW(hModule, L"Reboot required, setting REBOOT property to \"force\"");
|
---|
560 | HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force");
|
---|
561 | if (hr2 != ERROR_SUCCESS)
|
---|
562 | logStringW(hModule, L"Failed to set REBOOT property, error = 0x%x", hr2);
|
---|
563 | uRet = ERROR_SUCCESS; /* Never fail here. */
|
---|
564 | break;
|
---|
565 | }
|
---|
566 |
|
---|
567 | default:
|
---|
568 | logStringW(hModule, L"Converting unhandled HRESULT (0x%x) to ERROR_GEN_FAILURE", hr);
|
---|
569 | uRet = ERROR_GEN_FAILURE;
|
---|
570 | }
|
---|
571 | return uRet;
|
---|
572 | }
|
---|
573 |
|
---|
574 | static MSIHANDLE createNetCfgLockedMsgRecord(MSIHANDLE hModule)
|
---|
575 | {
|
---|
576 | MSIHANDLE hRecord = MsiCreateRecord(2);
|
---|
577 | if (hRecord)
|
---|
578 | {
|
---|
579 | UINT uErr = MsiRecordSetInteger(hRecord, 1, 25001);
|
---|
580 | if (uErr != ERROR_SUCCESS)
|
---|
581 | {
|
---|
582 | logStringW(hModule, L"createNetCfgLockedMsgRecord: MsiRecordSetInteger failed, error = 0x%x", uErr);
|
---|
583 | MsiCloseHandle(hRecord);
|
---|
584 | hRecord = NULL;
|
---|
585 | }
|
---|
586 | }
|
---|
587 | else
|
---|
588 | logStringW(hModule, L"createNetCfgLockedMsgRecord: Failed to create a record");
|
---|
589 |
|
---|
590 | return hRecord;
|
---|
591 | }
|
---|
592 |
|
---|
593 | static UINT doNetCfgInit(MSIHANDLE hModule, INetCfg **ppnc, BOOL bWrite)
|
---|
594 | {
|
---|
595 | MSIHANDLE hMsg = NULL;
|
---|
596 | UINT uErr = ERROR_GEN_FAILURE;
|
---|
597 | int MsgResult;
|
---|
598 | int cRetries = 0;
|
---|
599 |
|
---|
600 | do
|
---|
601 | {
|
---|
602 | LPWSTR lpszLockedBy;
|
---|
603 | HRESULT hr = VBoxNetCfgWinQueryINetCfg(ppnc, bWrite, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
|
---|
604 | if (hr != NETCFG_E_NO_WRITE_LOCK)
|
---|
605 | {
|
---|
606 | if (FAILED(hr))
|
---|
607 | logStringW(hModule, L"doNetCfgInit: VBoxNetCfgWinQueryINetCfg failed, error = 0x%x", hr);
|
---|
608 | uErr = errorConvertFromHResult(hModule, hr);
|
---|
609 | break;
|
---|
610 | }
|
---|
611 |
|
---|
612 | /* hr == NETCFG_E_NO_WRITE_LOCK */
|
---|
613 |
|
---|
614 | if (!lpszLockedBy)
|
---|
615 | {
|
---|
616 | logStringW(hModule, L"doNetCfgInit: lpszLockedBy == NULL, breaking");
|
---|
617 | break;
|
---|
618 | }
|
---|
619 |
|
---|
620 | /* on vista the 6to4svc.dll periodically maintains the lock for some reason,
|
---|
621 | * if this is the case, increase the wait period by retrying multiple times
|
---|
622 | * NOTE: we could alternatively increase the wait timeout,
|
---|
623 | * however it seems unneeded for most cases, e.g. in case some network connection property
|
---|
624 | * dialog is opened, it would be better to post a notification to the user as soon as possible
|
---|
625 | * rather than waiting for a longer period of time before displaying it */
|
---|
626 | if ( cRetries < VBOX_NETCFG_MAX_RETRIES
|
---|
627 | && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
|
---|
628 | {
|
---|
629 | cRetries++;
|
---|
630 | logStringW(hModule, L"doNetCfgInit: lpszLockedBy is 6to4svc.dll, retrying %d out of %d", cRetries, VBOX_NETCFG_MAX_RETRIES);
|
---|
631 | MsgResult = IDRETRY;
|
---|
632 | }
|
---|
633 | else
|
---|
634 | {
|
---|
635 | if (!hMsg)
|
---|
636 | {
|
---|
637 | hMsg = createNetCfgLockedMsgRecord(hModule);
|
---|
638 | if (!hMsg)
|
---|
639 | {
|
---|
640 | logStringW(hModule, L"doNetCfgInit: Failed to create a message record, breaking");
|
---|
641 | CoTaskMemFree(lpszLockedBy);
|
---|
642 | break;
|
---|
643 | }
|
---|
644 | }
|
---|
645 |
|
---|
646 | UINT rTmp = MsiRecordSetStringW(hMsg, 2, lpszLockedBy);
|
---|
647 | NonStandardAssert(rTmp == ERROR_SUCCESS);
|
---|
648 | if (rTmp != ERROR_SUCCESS)
|
---|
649 | {
|
---|
650 | logStringW(hModule, L"doNetCfgInit: MsiRecordSetStringW failed, error = 0x%x", rTmp);
|
---|
651 | CoTaskMemFree(lpszLockedBy);
|
---|
652 | break;
|
---|
653 | }
|
---|
654 |
|
---|
655 | MsgResult = MsiProcessMessage(hModule, (INSTALLMESSAGE)(INSTALLMESSAGE_USER | MB_RETRYCANCEL), hMsg);
|
---|
656 | NonStandardAssert(MsgResult == IDRETRY || MsgResult == IDCANCEL);
|
---|
657 | logStringW(hModule, L"doNetCfgInit: MsiProcessMessage returned (0x%x)", MsgResult);
|
---|
658 | }
|
---|
659 | CoTaskMemFree(lpszLockedBy);
|
---|
660 | } while(MsgResult == IDRETRY);
|
---|
661 |
|
---|
662 | if (hMsg)
|
---|
663 | MsiCloseHandle(hMsg);
|
---|
664 |
|
---|
665 | return uErr;
|
---|
666 | }
|
---|
667 |
|
---|
668 | static UINT vboxNetFltQueryInfArray(MSIHANDLE hModule, OUT LPWSTR pwszPtInf, OUT LPWSTR pwszMpInf, DWORD dwSize)
|
---|
669 | {
|
---|
670 | DWORD dwBuf = dwSize - RT_MAX(sizeof(NETFLT_PT_INF_REL_PATH), sizeof(NETFLT_MP_INF_REL_PATH));
|
---|
671 | UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", pwszPtInf, &dwBuf);
|
---|
672 | if ( uErr == ERROR_SUCCESS
|
---|
673 | && dwBuf)
|
---|
674 | {
|
---|
675 | wcscpy(pwszMpInf, pwszPtInf);
|
---|
676 |
|
---|
677 | wcsncat(pwszPtInf, NETFLT_PT_INF_REL_PATH, sizeof(NETFLT_PT_INF_REL_PATH));
|
---|
678 | logStringW(hModule, L"vboxNetFltQueryInfArray: INF 1: %s", pwszPtInf);
|
---|
679 |
|
---|
680 | wcsncat(pwszMpInf, NETFLT_MP_INF_REL_PATH, sizeof(NETFLT_MP_INF_REL_PATH));
|
---|
681 | logStringW(hModule, L"vboxNetFltQueryInfArray: INF 2: %s", pwszMpInf);
|
---|
682 | }
|
---|
683 | else if (uErr != ERROR_SUCCESS)
|
---|
684 | logStringW(hModule, L"vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = 0x%x", uErr);
|
---|
685 | else
|
---|
686 | {
|
---|
687 | logStringW(hModule, L"vboxNetFltQueryInfArray: Empty installation directory");
|
---|
688 | uErr = ERROR_GEN_FAILURE;
|
---|
689 | }
|
---|
690 |
|
---|
691 | return uErr;
|
---|
692 | }
|
---|
693 |
|
---|
694 | #endif /*VBOX_WITH_NETFLT*/
|
---|
695 |
|
---|
696 | UINT __stdcall UninstallNetFlt(MSIHANDLE hModule)
|
---|
697 | {
|
---|
698 | #ifdef VBOX_WITH_NETFLT
|
---|
699 | INetCfg *pNetCfg;
|
---|
700 | UINT uErr;
|
---|
701 |
|
---|
702 | netCfgLoggerEnable(hModule);
|
---|
703 |
|
---|
704 | BOOL bOldIntMode = SetupSetNonInteractiveMode(FALSE);
|
---|
705 |
|
---|
706 | __try
|
---|
707 | {
|
---|
708 | logStringW(hModule, L"Uninstalling NetFlt");
|
---|
709 |
|
---|
710 | uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
|
---|
711 | if (uErr == ERROR_SUCCESS)
|
---|
712 | {
|
---|
713 | HRESULT hr = VBoxNetCfgWinNetFltUninstall(pNetCfg);
|
---|
714 | if (hr != S_OK)
|
---|
715 | logStringW(hModule, L"UninstallNetFlt: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr);
|
---|
716 |
|
---|
717 | uErr = errorConvertFromHResult(hModule, hr);
|
---|
718 |
|
---|
719 | VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
|
---|
720 |
|
---|
721 | logStringW(hModule, L"Uninstalling NetFlt done, error = 0x%x", uErr);
|
---|
722 | }
|
---|
723 | else
|
---|
724 | logStringW(hModule, L"UninstallNetFlt: doNetCfgInit failed, error = 0x%x", uErr);
|
---|
725 | }
|
---|
726 | __finally
|
---|
727 | {
|
---|
728 | if (bOldIntMode)
|
---|
729 | {
|
---|
730 | /* The prev mode != FALSE, i.e. non-interactive. */
|
---|
731 | SetupSetNonInteractiveMode(bOldIntMode);
|
---|
732 | }
|
---|
733 | netCfgLoggerDisable();
|
---|
734 | }
|
---|
735 | #endif /* VBOX_WITH_NETFLT */
|
---|
736 |
|
---|
737 | /* Never fail the install even if we did not succeed. */
|
---|
738 | return ERROR_SUCCESS;
|
---|
739 | }
|
---|
740 |
|
---|
741 | UINT __stdcall InstallNetFlt(MSIHANDLE hModule)
|
---|
742 | {
|
---|
743 | #ifdef VBOX_WITH_NETFLT
|
---|
744 | UINT uErr;
|
---|
745 | INetCfg *pNetCfg;
|
---|
746 |
|
---|
747 | netCfgLoggerEnable(hModule);
|
---|
748 |
|
---|
749 | BOOL bOldIntMode = SetupSetNonInteractiveMode(FALSE);
|
---|
750 |
|
---|
751 | __try
|
---|
752 | {
|
---|
753 |
|
---|
754 | logStringW(hModule, L"InstallNetFlt: Installing NetFlt");
|
---|
755 |
|
---|
756 | uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
|
---|
757 | if (uErr == ERROR_SUCCESS)
|
---|
758 | {
|
---|
759 | WCHAR wszPtInf[MAX_PATH];
|
---|
760 | WCHAR wszMpInf[MAX_PATH];
|
---|
761 | uErr = vboxNetFltQueryInfArray(hModule, wszPtInf, wszMpInf, sizeof(wszMpInf));
|
---|
762 | if (uErr == ERROR_SUCCESS)
|
---|
763 | {
|
---|
764 | LPCWSTR const apwszInfs[] = { wszPtInf, wszMpInf };
|
---|
765 | HRESULT hr = VBoxNetCfgWinNetFltInstall(pNetCfg, &apwszInfs[0], RT_ELEMENTS(apwszInfs));
|
---|
766 | if (FAILED(hr))
|
---|
767 | logStringW(hModule, L"InstallNetFlt: VBoxNetCfgWinNetFltInstall failed, error = 0x%x", hr);
|
---|
768 |
|
---|
769 | uErr = errorConvertFromHResult(hModule, hr);
|
---|
770 | }
|
---|
771 | else
|
---|
772 | logStringW(hModule, L"InstallNetFlt: vboxNetFltQueryInfArray failed, error = 0x%x", uErr);
|
---|
773 |
|
---|
774 | VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
|
---|
775 |
|
---|
776 | logStringW(hModule, L"InstallNetFlt: Done");
|
---|
777 | }
|
---|
778 | else
|
---|
779 | logStringW(hModule, L"InstallNetFlt: doNetCfgInit failed, error = 0x%x", uErr);
|
---|
780 | }
|
---|
781 | __finally
|
---|
782 | {
|
---|
783 | if (bOldIntMode)
|
---|
784 | {
|
---|
785 | /* The prev mode != FALSE, i.e. non-interactive. */
|
---|
786 | SetupSetNonInteractiveMode(bOldIntMode);
|
---|
787 | }
|
---|
788 | netCfgLoggerDisable();
|
---|
789 | }
|
---|
790 | #endif /* VBOX_WITH_NETFLT */
|
---|
791 |
|
---|
792 | /* Never fail the install even if we did not succeed. */
|
---|
793 | return ERROR_SUCCESS;
|
---|
794 | }
|
---|
795 |
|
---|
796 |
|
---|
797 | UINT __stdcall UninstallNetLwf(MSIHANDLE hModule)
|
---|
798 | {
|
---|
799 | #ifdef VBOX_WITH_NETFLT
|
---|
800 | INetCfg *pNetCfg;
|
---|
801 | UINT uErr;
|
---|
802 |
|
---|
803 | netCfgLoggerEnable(hModule);
|
---|
804 |
|
---|
805 | BOOL bOldIntMode = SetupSetNonInteractiveMode(FALSE);
|
---|
806 |
|
---|
807 | __try
|
---|
808 | {
|
---|
809 | logStringW(hModule, L"Uninstalling NetLwf");
|
---|
810 |
|
---|
811 | uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
|
---|
812 | if (uErr == ERROR_SUCCESS)
|
---|
813 | {
|
---|
814 | HRESULT hr = VBoxNetCfgWinNetLwfUninstall(pNetCfg);
|
---|
815 | if (hr != S_OK)
|
---|
816 | logStringW(hModule, L"UninstallNetLwf: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr);
|
---|
817 |
|
---|
818 | uErr = errorConvertFromHResult(hModule, hr);
|
---|
819 |
|
---|
820 | VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
|
---|
821 |
|
---|
822 | logStringW(hModule, L"Uninstalling NetLwf done, error = 0x%x", uErr);
|
---|
823 | }
|
---|
824 | else
|
---|
825 | logStringW(hModule, L"UninstallNetLwf: doNetCfgInit failed, error = 0x%x", uErr);
|
---|
826 | }
|
---|
827 | __finally
|
---|
828 | {
|
---|
829 | if (bOldIntMode)
|
---|
830 | {
|
---|
831 | /* The prev mode != FALSE, i.e. non-interactive. */
|
---|
832 | SetupSetNonInteractiveMode(bOldIntMode);
|
---|
833 | }
|
---|
834 | netCfgLoggerDisable();
|
---|
835 | }
|
---|
836 | #endif /* VBOX_WITH_NETFLT */
|
---|
837 |
|
---|
838 | /* Never fail the install even if we did not succeed. */
|
---|
839 | return ERROR_SUCCESS;
|
---|
840 | }
|
---|
841 |
|
---|
842 | UINT __stdcall InstallNetLwf(MSIHANDLE hModule)
|
---|
843 | {
|
---|
844 | #ifdef VBOX_WITH_NETFLT
|
---|
845 | UINT uErr;
|
---|
846 | INetCfg *pNetCfg;
|
---|
847 |
|
---|
848 | netCfgLoggerEnable(hModule);
|
---|
849 |
|
---|
850 | BOOL bOldIntMode = SetupSetNonInteractiveMode(FALSE);
|
---|
851 |
|
---|
852 | __try
|
---|
853 | {
|
---|
854 |
|
---|
855 | logStringW(hModule, L"InstallNetLwf: Installing NetLwf");
|
---|
856 |
|
---|
857 | uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
|
---|
858 | if (uErr == ERROR_SUCCESS)
|
---|
859 | {
|
---|
860 | WCHAR wszInfName[] = NETLWF_INF_NAME;
|
---|
861 | WCHAR wszInf[MAX_PATH];
|
---|
862 | DWORD cchInf = RT_ELEMENTS(wszInf) - sizeof(NETLWF_INF_NAME) - 1;
|
---|
863 | UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszInf, &cchInf);
|
---|
864 | if (uErr == ERROR_SUCCESS)
|
---|
865 | {
|
---|
866 | if (cchInf)
|
---|
867 | {
|
---|
868 | if (wszInf[cchInf - 1] != L'\\')
|
---|
869 | {
|
---|
870 | wszInf[cchInf++] = L'\\';
|
---|
871 | wszInf[cchInf] = L'\0';
|
---|
872 | }
|
---|
873 |
|
---|
874 | wcscat(wszInf, NETLWF_INF_NAME);
|
---|
875 |
|
---|
876 | HRESULT hr = VBoxNetCfgWinNetLwfInstall(pNetCfg, wszInf);
|
---|
877 | if (FAILED(hr))
|
---|
878 | logStringW(hModule, L"InstallNetLwf: VBoxNetCfgWinNetLwfInstall failed, error = 0x%x", hr);
|
---|
879 |
|
---|
880 | uErr = errorConvertFromHResult(hModule, hr);
|
---|
881 | }
|
---|
882 | else
|
---|
883 | {
|
---|
884 | logStringW(hModule, L"vboxNetFltQueryInfArray: Empty installation directory");
|
---|
885 | uErr = ERROR_GEN_FAILURE;
|
---|
886 | }
|
---|
887 | }
|
---|
888 | else
|
---|
889 | logStringW(hModule, L"vboxNetFltQueryInfArray: MsiGetPropertyW failed, error = 0x%x", uErr);
|
---|
890 |
|
---|
891 | VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
|
---|
892 |
|
---|
893 | logStringW(hModule, L"InstallNetLwf: Done");
|
---|
894 | }
|
---|
895 | else
|
---|
896 | logStringW(hModule, L"InstallNetLwf: doNetCfgInit failed, error = 0x%x", uErr);
|
---|
897 | }
|
---|
898 | __finally
|
---|
899 | {
|
---|
900 | if (bOldIntMode)
|
---|
901 | {
|
---|
902 | /* The prev mode != FALSE, i.e. non-interactive. */
|
---|
903 | SetupSetNonInteractiveMode(bOldIntMode);
|
---|
904 | }
|
---|
905 | netCfgLoggerDisable();
|
---|
906 | }
|
---|
907 | #endif /* VBOX_WITH_NETFLT */
|
---|
908 |
|
---|
909 | /* Never fail the install even if we did not succeed. */
|
---|
910 | return ERROR_SUCCESS;
|
---|
911 | }
|
---|
912 |
|
---|
913 |
|
---|
914 | #if 0
|
---|
915 | static BOOL RenameHostOnlyConnectionsCallback(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext)
|
---|
916 | {
|
---|
917 | WCHAR DevName[256];
|
---|
918 | DWORD winEr;
|
---|
919 |
|
---|
920 | if (SetupDiGetDeviceRegistryPropertyW(hDevInfo, pDev,
|
---|
921 | SPDRP_FRIENDLYNAME , /* IN DWORD Property,*/
|
---|
922 | NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/
|
---|
923 | (PBYTE)DevName, /*OUT PBYTE PropertyBuffer,*/
|
---|
924 | sizeof(DevName), /* IN DWORD PropertyBufferSize,*/
|
---|
925 | NULL /*OUT PDWORD RequiredSize OPTIONAL*/
|
---|
926 | ))
|
---|
927 | {
|
---|
928 | HKEY hKey = SetupDiOpenDevRegKey(hDevInfo, pDev,
|
---|
929 | DICS_FLAG_GLOBAL, /* IN DWORD Scope,*/
|
---|
930 | 0, /*IN DWORD HwProfile, */
|
---|
931 | DIREG_DRV, /* IN DWORD KeyType, */
|
---|
932 | KEY_READ /*IN REGSAM samDesired*/
|
---|
933 | );
|
---|
934 | NonStandardAssert(hKey != INVALID_HANDLE_VALUE);
|
---|
935 | if (hKey != INVALID_HANDLE_VALUE)
|
---|
936 | {
|
---|
937 | WCHAR guid[50];
|
---|
938 | DWORD cbGuid=sizeof(guid);
|
---|
939 | winEr = RegQueryValueExW(hKey,
|
---|
940 | L"NetCfgInstanceId", /*__in_opt LPCTSTR lpValueName,*/
|
---|
941 | NULL, /*__reserved LPDWORD lpReserved,*/
|
---|
942 | NULL, /*__out_opt LPDWORD lpType,*/
|
---|
943 | (LPBYTE)guid, /*__out_opt LPBYTE lpData,*/
|
---|
944 | &cbGuid /*guid__inout_opt LPDWORD lpcbData*/
|
---|
945 | );
|
---|
946 | NonStandardAssert(winEr == ERROR_SUCCESS);
|
---|
947 | if (winEr == ERROR_SUCCESS)
|
---|
948 | {
|
---|
949 | WCHAR ConnectoinName[128];
|
---|
950 | ULONG cbName = sizeof(ConnectoinName);
|
---|
951 |
|
---|
952 | HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName (DevName, ConnectoinName, &cbName);
|
---|
953 | NonStandardAssert(hr == S_OK);
|
---|
954 | if (SUCCEEDED(hr))
|
---|
955 | {
|
---|
956 | hr = VBoxNetCfgWinRenameConnection(guid, ConnectoinName);
|
---|
957 | NonStandardAssert(hr == S_OK);
|
---|
958 | }
|
---|
959 | }
|
---|
960 | }
|
---|
961 | RegCloseKey(hKey);
|
---|
962 | }
|
---|
963 | else
|
---|
964 | {
|
---|
965 | NonStandardAssert(0);
|
---|
966 | }
|
---|
967 |
|
---|
968 | return TRUE;
|
---|
969 | }
|
---|
970 | #endif
|
---|
971 |
|
---|
972 | static UINT _createHostOnlyInterface(MSIHANDLE hModule, LPCWSTR pwszId, LPCWSTR pwszInfName)
|
---|
973 | {
|
---|
974 | #ifdef VBOX_WITH_NETFLT
|
---|
975 | netCfgLoggerEnable(hModule);
|
---|
976 |
|
---|
977 | BOOL bSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
|
---|
978 | bool bSetStaticIp = true;
|
---|
979 |
|
---|
980 | logStringW(hModule, L"CreateHostOnlyInterface: Creating host-only interface");
|
---|
981 |
|
---|
982 | HRESULT hr;
|
---|
983 |
|
---|
984 | GUID guid;
|
---|
985 | WCHAR wszMpInf[MAX_PATH];
|
---|
986 | DWORD cchMpInf = RT_ELEMENTS(wszMpInf) - wcslen(pwszInfName) - 1 - 1;
|
---|
987 | LPCWSTR pwszInfPath = NULL;
|
---|
988 | bool bIsFile = false;
|
---|
989 | UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &cchMpInf);
|
---|
990 | if (uErr == ERROR_SUCCESS)
|
---|
991 | {
|
---|
992 | if (cchMpInf)
|
---|
993 | {
|
---|
994 | logStringW(hModule, L"CreateHostOnlyInterface: NetAdpDir property = %s", wszMpInf);
|
---|
995 | if (wszMpInf[cchMpInf - 1] != L'\\')
|
---|
996 | {
|
---|
997 | wszMpInf[cchMpInf++] = L'\\';
|
---|
998 | wszMpInf[cchMpInf] = L'\0';
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | wcscat(wszMpInf, pwszInfName);
|
---|
1002 | pwszInfPath = wszMpInf;
|
---|
1003 | bIsFile = true;
|
---|
1004 |
|
---|
1005 | logStringW(hModule, L"CreateHostOnlyInterface: Resulting INF path = %s", pwszInfPath);
|
---|
1006 | }
|
---|
1007 | else
|
---|
1008 | logStringW(hModule, L"CreateHostOnlyInterface: VBox installation path is empty");
|
---|
1009 | }
|
---|
1010 | else
|
---|
1011 | logStringW(hModule, L"CreateHostOnlyInterface: Unable to retrieve VBox installation path, error = 0x%x", uErr);
|
---|
1012 |
|
---|
1013 | /* Make sure the inf file is installed. */
|
---|
1014 | if (pwszInfPath != NULL && bIsFile)
|
---|
1015 | {
|
---|
1016 | logStringW(hModule, L"CreateHostOnlyInterface: Calling VBoxDrvCfgInfInstall(%s)", pwszInfPath);
|
---|
1017 | hr = VBoxDrvCfgInfInstall(pwszInfPath);
|
---|
1018 | logStringW(hModule, L"CreateHostOnlyInterface: VBoxDrvCfgInfInstall returns 0x%x", hr);
|
---|
1019 | if (FAILED(hr))
|
---|
1020 | logStringW(hModule, L"CreateHostOnlyInterface: Failed to install INF file, error = 0x%x", hr);
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | if (SUCCEEDED(hr))
|
---|
1024 | {
|
---|
1025 | //first, try to update Host Only Network Interface
|
---|
1026 | BOOL fRebootRequired = FALSE;
|
---|
1027 | hr = VBoxNetCfgWinUpdateHostOnlyNetworkInterface(pwszInfPath, &fRebootRequired, pwszId);
|
---|
1028 | if (SUCCEEDED(hr))
|
---|
1029 | {
|
---|
1030 | if (fRebootRequired)
|
---|
1031 | {
|
---|
1032 | logStringW(hModule, L"UpdateHostOnlyInterfaces: Reboot required, setting REBOOT property to force");
|
---|
1033 | HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force");
|
---|
1034 | if (hr2 != ERROR_SUCCESS)
|
---|
1035 | logStringW(hModule, L"UpdateHostOnlyInterfaces: Failed to set REBOOT property, error = 0x%x", hr2);
|
---|
1036 | }
|
---|
1037 | }
|
---|
1038 | else
|
---|
1039 | logStringW(hModule, L"UpdateHostOnlyInterfaces: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = 0x%x", hr);
|
---|
1040 | //in fail case call CreateHostOnlyInterface
|
---|
1041 | if (FAILED(hr))
|
---|
1042 | {
|
---|
1043 | logStringW(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinCreateHostOnlyNetworkInterface");
|
---|
1044 | hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface(pwszInfPath, bIsFile, &guid, NULL, NULL);
|
---|
1045 | logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface returns 0x%x", hr);
|
---|
1046 | if (SUCCEEDED(hr))
|
---|
1047 | {
|
---|
1048 | ULONG ip = inet_addr("192.168.56.1");
|
---|
1049 | ULONG mask = inet_addr("255.255.255.0");
|
---|
1050 | logStringW(hModule, L"CreateHostOnlyInterface: calling VBoxNetCfgWinEnableStaticIpConfig");
|
---|
1051 | hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask);
|
---|
1052 | logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig returns 0x%x", hr);
|
---|
1053 | if (FAILED(hr))
|
---|
1054 | logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinEnableStaticIpConfig failed, error = 0x%x", hr);
|
---|
1055 | }
|
---|
1056 | else
|
---|
1057 | logStringW(hModule, L"CreateHostOnlyInterface: VBoxNetCfgWinCreateHostOnlyNetworkInterface failed, error = 0x%x", hr);
|
---|
1058 | }
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | if (SUCCEEDED(hr))
|
---|
1062 | logStringW(hModule, L"CreateHostOnlyInterface: Creating host-only interface done");
|
---|
1063 |
|
---|
1064 | /* Restore original setup mode. */
|
---|
1065 | logStringW(hModule, L"CreateHostOnlyInterface: Almost done...");
|
---|
1066 | if (bSetupModeInteractive)
|
---|
1067 | SetupSetNonInteractiveMode(bSetupModeInteractive);
|
---|
1068 |
|
---|
1069 | netCfgLoggerDisable();
|
---|
1070 |
|
---|
1071 | #endif /* VBOX_WITH_NETFLT */
|
---|
1072 |
|
---|
1073 | logStringW(hModule, L"CreateHostOnlyInterface: Returns success (ignoring all failures)");
|
---|
1074 | /* Never fail the install even if we did not succeed. */
|
---|
1075 | return ERROR_SUCCESS;
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | UINT __stdcall CreateHostOnlyInterface(MSIHANDLE hModule)
|
---|
1079 | {
|
---|
1080 | return _createHostOnlyInterface(hModule, NETADP_ID, L"VBoxNetAdp.inf");
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | UINT __stdcall Ndis6CreateHostOnlyInterface(MSIHANDLE hModule)
|
---|
1084 | {
|
---|
1085 | return _createHostOnlyInterface(hModule, NETADP_ID, L"VBoxNetAdp6.inf");
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 | static UINT _removeHostOnlyInterfaces(MSIHANDLE hModule, LPCWSTR pwszId)
|
---|
1089 | {
|
---|
1090 | #ifdef VBOX_WITH_NETFLT
|
---|
1091 | netCfgLoggerEnable(hModule);
|
---|
1092 |
|
---|
1093 | logStringW(hModule, L"RemoveHostOnlyInterfaces: Removing all host-only interfaces");
|
---|
1094 |
|
---|
1095 | BOOL bSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
|
---|
1096 |
|
---|
1097 | HRESULT hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(pwszId);
|
---|
1098 | if (SUCCEEDED(hr))
|
---|
1099 | {
|
---|
1100 | hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", pwszId, SUOI_FORCEDELETE/* could be SUOI_FORCEDELETE */);
|
---|
1101 | if (FAILED(hr))
|
---|
1102 | {
|
---|
1103 | logStringW(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully, but failed to remove INF files");
|
---|
1104 | }
|
---|
1105 | else
|
---|
1106 | logStringW(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstalled successfully");
|
---|
1107 |
|
---|
1108 | }
|
---|
1109 | else
|
---|
1110 | logStringW(hModule, L"RemoveHostOnlyInterfaces: NetAdp uninstall failed, hr = 0x%x", hr);
|
---|
1111 |
|
---|
1112 | /* Restore original setup mode. */
|
---|
1113 | if (bSetupModeInteractive)
|
---|
1114 | SetupSetNonInteractiveMode(bSetupModeInteractive);
|
---|
1115 |
|
---|
1116 | netCfgLoggerDisable();
|
---|
1117 | #endif /* VBOX_WITH_NETFLT */
|
---|
1118 |
|
---|
1119 | /* Never fail the install even if we did not succeed. */
|
---|
1120 | return ERROR_SUCCESS;
|
---|
1121 | }
|
---|
1122 |
|
---|
1123 | UINT __stdcall RemoveHostOnlyInterfaces(MSIHANDLE hModule)
|
---|
1124 | {
|
---|
1125 | return _removeHostOnlyInterfaces(hModule, NETADP_ID);
|
---|
1126 | }
|
---|
1127 |
|
---|
1128 | static UINT _stopHostOnlyInterfaces(MSIHANDLE hModule, LPCWSTR pwszId)
|
---|
1129 | {
|
---|
1130 | #ifdef VBOX_WITH_NETFLT
|
---|
1131 | netCfgLoggerEnable(hModule);
|
---|
1132 |
|
---|
1133 | logStringW(hModule, L"StopHostOnlyInterfaces: Stopping all host-only interfaces");
|
---|
1134 |
|
---|
1135 | BOOL bSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
|
---|
1136 |
|
---|
1137 | HRESULT hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(pwszId, VBOXNECTFGWINPROPCHANGE_TYPE_DISABLE);
|
---|
1138 | if (SUCCEEDED(hr))
|
---|
1139 | {
|
---|
1140 | logStringW(hModule, L"StopHostOnlyInterfaces: Disabling host interfaces was successful, hr = 0x%x", hr);
|
---|
1141 | }
|
---|
1142 | else
|
---|
1143 | logStringW(hModule, L"StopHostOnlyInterfaces: Disabling host interfaces failed, hr = 0x%x", hr);
|
---|
1144 |
|
---|
1145 | /* Restore original setup mode. */
|
---|
1146 | if (bSetupModeInteractive)
|
---|
1147 | SetupSetNonInteractiveMode(bSetupModeInteractive);
|
---|
1148 |
|
---|
1149 | netCfgLoggerDisable();
|
---|
1150 | #endif /* VBOX_WITH_NETFLT */
|
---|
1151 |
|
---|
1152 | /* Never fail the install even if we did not succeed. */
|
---|
1153 | return ERROR_SUCCESS;
|
---|
1154 | }
|
---|
1155 |
|
---|
1156 | UINT __stdcall StopHostOnlyInterfaces(MSIHANDLE hModule)
|
---|
1157 | {
|
---|
1158 | return _stopHostOnlyInterfaces(hModule, NETADP_ID);
|
---|
1159 | }
|
---|
1160 |
|
---|
1161 | static UINT _updateHostOnlyInterfaces(MSIHANDLE hModule, LPCWSTR pwszInfName, LPCWSTR pwszId)
|
---|
1162 | {
|
---|
1163 | #ifdef VBOX_WITH_NETFLT
|
---|
1164 | netCfgLoggerEnable(hModule);
|
---|
1165 |
|
---|
1166 | logStringW(hModule, L"UpdateHostOnlyInterfaces: Updating all host-only interfaces");
|
---|
1167 |
|
---|
1168 | BOOL bSetupModeInteractive = SetupSetNonInteractiveMode(FALSE);
|
---|
1169 |
|
---|
1170 | WCHAR wszMpInf[MAX_PATH];
|
---|
1171 | DWORD cchMpInf = RT_ELEMENTS(wszMpInf) - wcslen(pwszInfName) - 1 - 1;
|
---|
1172 | LPCWSTR pwszInfPath = NULL;
|
---|
1173 | bool bIsFile = false;
|
---|
1174 | UINT uErr = MsiGetPropertyW(hModule, L"CustomActionData", wszMpInf, &cchMpInf);
|
---|
1175 | if (uErr == ERROR_SUCCESS)
|
---|
1176 | {
|
---|
1177 | if (cchMpInf)
|
---|
1178 | {
|
---|
1179 | logStringW(hModule, L"UpdateHostOnlyInterfaces: NetAdpDir property = %s", wszMpInf);
|
---|
1180 | if (wszMpInf[cchMpInf - 1] != L'\\')
|
---|
1181 | {
|
---|
1182 | wszMpInf[cchMpInf++] = L'\\';
|
---|
1183 | wszMpInf[cchMpInf] = L'\0';
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 | wcscat(wszMpInf, pwszInfName);
|
---|
1187 | pwszInfPath = wszMpInf;
|
---|
1188 | bIsFile = true;
|
---|
1189 |
|
---|
1190 | logStringW(hModule, L"UpdateHostOnlyInterfaces: Resulting INF path = %s", pwszInfPath);
|
---|
1191 |
|
---|
1192 | DWORD attrFile = GetFileAttributesW(pwszInfPath);
|
---|
1193 | if (attrFile == INVALID_FILE_ATTRIBUTES)
|
---|
1194 | {
|
---|
1195 | DWORD dwErr = GetLastError();
|
---|
1196 | logStringW(hModule, L"UpdateHostOnlyInterfaces: File \"%s\" not found, dwErr=%ld",
|
---|
1197 | pwszInfPath, dwErr);
|
---|
1198 | }
|
---|
1199 | else
|
---|
1200 | {
|
---|
1201 | logStringW(hModule, L"UpdateHostOnlyInterfaces: File \"%s\" exists",
|
---|
1202 | pwszInfPath);
|
---|
1203 |
|
---|
1204 | BOOL fRebootRequired = FALSE;
|
---|
1205 | HRESULT hr = VBoxNetCfgWinUpdateHostOnlyNetworkInterface(pwszInfPath, &fRebootRequired, pwszId);
|
---|
1206 | if (SUCCEEDED(hr))
|
---|
1207 | {
|
---|
1208 | if (fRebootRequired)
|
---|
1209 | {
|
---|
1210 | logStringW(hModule, L"UpdateHostOnlyInterfaces: Reboot required, setting REBOOT property to force");
|
---|
1211 | HRESULT hr2 = MsiSetPropertyW(hModule, L"REBOOT", L"Force");
|
---|
1212 | if (hr2 != ERROR_SUCCESS)
|
---|
1213 | logStringW(hModule, L"UpdateHostOnlyInterfaces: Failed to set REBOOT property, error = 0x%x", hr2);
|
---|
1214 | }
|
---|
1215 | }
|
---|
1216 | else
|
---|
1217 | logStringW(hModule, L"UpdateHostOnlyInterfaces: VBoxNetCfgWinUpdateHostOnlyNetworkInterface failed, hr = 0x%x", hr);
|
---|
1218 | }
|
---|
1219 | }
|
---|
1220 | else
|
---|
1221 | logStringW(hModule, L"UpdateHostOnlyInterfaces: VBox installation path is empty");
|
---|
1222 | }
|
---|
1223 | else
|
---|
1224 | logStringW(hModule, L"UpdateHostOnlyInterfaces: Unable to retrieve VBox installation path, error = 0x%x", uErr);
|
---|
1225 |
|
---|
1226 | /* Restore original setup mode. */
|
---|
1227 | if (bSetupModeInteractive)
|
---|
1228 | SetupSetNonInteractiveMode(bSetupModeInteractive);
|
---|
1229 |
|
---|
1230 | netCfgLoggerDisable();
|
---|
1231 | #endif /* VBOX_WITH_NETFLT */
|
---|
1232 |
|
---|
1233 | /* Never fail the install even if we did not succeed. */
|
---|
1234 | return ERROR_SUCCESS;
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 | UINT __stdcall UpdateHostOnlyInterfaces(MSIHANDLE hModule)
|
---|
1238 | {
|
---|
1239 | return _updateHostOnlyInterfaces(hModule, L"VBoxNetAdp.inf", NETADP_ID);
|
---|
1240 | }
|
---|
1241 |
|
---|
1242 | UINT __stdcall Ndis6UpdateHostOnlyInterfaces(MSIHANDLE hModule)
|
---|
1243 | {
|
---|
1244 | return _updateHostOnlyInterfaces(hModule, L"VBoxNetAdp6.inf", NETADP_ID);
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 | static UINT _uninstallNetAdp(MSIHANDLE hModule, LPCWSTR pwszId)
|
---|
1248 | {
|
---|
1249 | #ifdef VBOX_WITH_NETFLT
|
---|
1250 | INetCfg *pNetCfg;
|
---|
1251 | UINT uErr;
|
---|
1252 |
|
---|
1253 | netCfgLoggerEnable(hModule);
|
---|
1254 |
|
---|
1255 | BOOL bOldIntMode = SetupSetNonInteractiveMode(FALSE);
|
---|
1256 |
|
---|
1257 | __try
|
---|
1258 | {
|
---|
1259 | logStringW(hModule, L"Uninstalling NetAdp");
|
---|
1260 |
|
---|
1261 | uErr = doNetCfgInit(hModule, &pNetCfg, TRUE);
|
---|
1262 | if (uErr == ERROR_SUCCESS)
|
---|
1263 | {
|
---|
1264 | HRESULT hr = VBoxNetCfgWinNetAdpUninstall(pNetCfg, pwszId);
|
---|
1265 | if (hr != S_OK)
|
---|
1266 | logStringW(hModule, L"UninstallNetAdp: VBoxNetCfgWinUninstallComponent failed, error = 0x%x", hr);
|
---|
1267 |
|
---|
1268 | uErr = errorConvertFromHResult(hModule, hr);
|
---|
1269 |
|
---|
1270 | VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
|
---|
1271 |
|
---|
1272 | logStringW(hModule, L"Uninstalling NetAdp done, error = 0x%x", uErr);
|
---|
1273 | }
|
---|
1274 | else
|
---|
1275 | logStringW(hModule, L"UninstallNetAdp: doNetCfgInit failed, error = 0x%x", uErr);
|
---|
1276 | }
|
---|
1277 | __finally
|
---|
1278 | {
|
---|
1279 | if (bOldIntMode)
|
---|
1280 | {
|
---|
1281 | /* The prev mode != FALSE, i.e. non-interactive. */
|
---|
1282 | SetupSetNonInteractiveMode(bOldIntMode);
|
---|
1283 | }
|
---|
1284 | netCfgLoggerDisable();
|
---|
1285 | }
|
---|
1286 | #endif /* VBOX_WITH_NETFLT */
|
---|
1287 |
|
---|
1288 | /* Never fail the install even if we did not succeed. */
|
---|
1289 | return ERROR_SUCCESS;
|
---|
1290 | }
|
---|
1291 |
|
---|
1292 | UINT __stdcall UninstallNetAdp(MSIHANDLE hModule)
|
---|
1293 | {
|
---|
1294 | return _uninstallNetAdp(hModule, NETADP_ID);
|
---|
1295 | }
|
---|
1296 |
|
---|
1297 | static bool isTAPDevice(const WCHAR *pwszGUID)
|
---|
1298 | {
|
---|
1299 | HKEY hNetcard;
|
---|
1300 | bool bIsTapDevice = false;
|
---|
1301 | LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
---|
1302 | L"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}",
|
---|
1303 | 0, KEY_READ, &hNetcard);
|
---|
1304 | if (lStatus != ERROR_SUCCESS)
|
---|
1305 | return false;
|
---|
1306 |
|
---|
1307 | int i = 0;
|
---|
1308 | for (;;)
|
---|
1309 | {
|
---|
1310 | WCHAR wszEnumName[256];
|
---|
1311 | WCHAR wszNetCfgInstanceId[256];
|
---|
1312 | DWORD dwKeyType;
|
---|
1313 | HKEY hNetCardGUID;
|
---|
1314 |
|
---|
1315 | DWORD dwLen = sizeof(wszEnumName);
|
---|
1316 | lStatus = RegEnumKeyExW(hNetcard, i, wszEnumName, &dwLen, NULL, NULL, NULL, NULL);
|
---|
1317 | if (lStatus != ERROR_SUCCESS)
|
---|
1318 | break;
|
---|
1319 |
|
---|
1320 | lStatus = RegOpenKeyExW(hNetcard, wszEnumName, 0, KEY_READ, &hNetCardGUID);
|
---|
1321 | if (lStatus == ERROR_SUCCESS)
|
---|
1322 | {
|
---|
1323 | dwLen = sizeof(wszNetCfgInstanceId);
|
---|
1324 | lStatus = RegQueryValueExW(hNetCardGUID, L"NetCfgInstanceId", NULL, &dwKeyType, (LPBYTE)wszNetCfgInstanceId, &dwLen);
|
---|
1325 | if ( lStatus == ERROR_SUCCESS
|
---|
1326 | && dwKeyType == REG_SZ)
|
---|
1327 | {
|
---|
1328 | WCHAR wszNetProductName[256];
|
---|
1329 | WCHAR wszNetProviderName[256];
|
---|
1330 |
|
---|
1331 | wszNetProductName[0] = 0;
|
---|
1332 | dwLen = sizeof(wszNetProductName);
|
---|
1333 | lStatus = RegQueryValueExW(hNetCardGUID, L"ProductName", NULL, &dwKeyType, (LPBYTE)wszNetProductName, &dwLen);
|
---|
1334 |
|
---|
1335 | wszNetProviderName[0] = 0;
|
---|
1336 | dwLen = sizeof(wszNetProviderName);
|
---|
1337 | lStatus = RegQueryValueExW(hNetCardGUID, L"ProviderName", NULL, &dwKeyType, (LPBYTE)wszNetProviderName, &dwLen);
|
---|
1338 |
|
---|
1339 | if ( !wcscmp(wszNetCfgInstanceId, pwszGUID)
|
---|
1340 | && !wcscmp(wszNetProductName, L"VirtualBox TAP Adapter")
|
---|
1341 | && ( (!wcscmp(wszNetProviderName, L"innotek GmbH")) /* Legacy stuff. */
|
---|
1342 | || (!wcscmp(wszNetProviderName, L"Sun Microsystems, Inc.")) /* Legacy stuff. */
|
---|
1343 | || (!wcscmp(wszNetProviderName, MY_WTEXT(VBOX_VENDOR))) /* Reflects current vendor string. */
|
---|
1344 | )
|
---|
1345 | )
|
---|
1346 | {
|
---|
1347 | bIsTapDevice = true;
|
---|
1348 | RegCloseKey(hNetCardGUID);
|
---|
1349 | break;
|
---|
1350 | }
|
---|
1351 | }
|
---|
1352 | RegCloseKey(hNetCardGUID);
|
---|
1353 | }
|
---|
1354 | ++i;
|
---|
1355 | }
|
---|
1356 |
|
---|
1357 | RegCloseKey(hNetcard);
|
---|
1358 | return bIsTapDevice;
|
---|
1359 | }
|
---|
1360 |
|
---|
1361 | #define SetErrBreak(strAndArgs) \
|
---|
1362 | if (1) { \
|
---|
1363 | rc = 0; \
|
---|
1364 | logStringW(hModule, strAndArgs); \
|
---|
1365 | break; \
|
---|
1366 | } else do {} while (0)
|
---|
1367 |
|
---|
1368 | int removeNetworkInterface(MSIHANDLE hModule, const WCHAR *pwszGUID)
|
---|
1369 | {
|
---|
1370 | int rc = 1;
|
---|
1371 | do
|
---|
1372 | {
|
---|
1373 | WCHAR wszPnPInstanceId[512] = {0};
|
---|
1374 |
|
---|
1375 | /* We have to find the device instance ID through a registry search */
|
---|
1376 |
|
---|
1377 | HKEY hkeyNetwork = 0;
|
---|
1378 | HKEY hkeyConnection = 0;
|
---|
1379 |
|
---|
1380 | do /* break-loop */
|
---|
1381 | {
|
---|
1382 | WCHAR wszRegLocation[256];
|
---|
1383 | swprintf(wszRegLocation,
|
---|
1384 | L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s",
|
---|
1385 | pwszGUID);
|
---|
1386 | LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszRegLocation, 0, KEY_READ, &hkeyNetwork);
|
---|
1387 | if ((lStatus != ERROR_SUCCESS) || !hkeyNetwork)
|
---|
1388 | SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [1]", wszRegLocation));
|
---|
1389 |
|
---|
1390 | lStatus = RegOpenKeyExW(hkeyNetwork, L"Connection", 0, KEY_READ, &hkeyConnection);
|
---|
1391 | if ((lStatus != ERROR_SUCCESS) || !hkeyConnection)
|
---|
1392 | SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [2]", wszRegLocation));
|
---|
1393 |
|
---|
1394 | DWORD len = sizeof(wszPnPInstanceId);
|
---|
1395 | DWORD dwKeyType;
|
---|
1396 | lStatus = RegQueryValueExW(hkeyConnection, L"PnPInstanceID", NULL,
|
---|
1397 | &dwKeyType, (LPBYTE)&wszPnPInstanceId[0], &len);
|
---|
1398 | if ((lStatus != ERROR_SUCCESS) || (dwKeyType != REG_SZ))
|
---|
1399 | SetErrBreak((L"VBox HostInterfaces: Host interface network was not found in registry (%s)! [3]", wszRegLocation));
|
---|
1400 | }
|
---|
1401 | while (0);
|
---|
1402 |
|
---|
1403 | if (hkeyConnection)
|
---|
1404 | RegCloseKey(hkeyConnection);
|
---|
1405 | if (hkeyNetwork)
|
---|
1406 | RegCloseKey(hkeyNetwork);
|
---|
1407 |
|
---|
1408 | /*
|
---|
1409 | * Now we are going to enumerate all network devices and
|
---|
1410 | * wait until we encounter the right device instance ID
|
---|
1411 | */
|
---|
1412 |
|
---|
1413 | HDEVINFO hDeviceInfo = INVALID_HANDLE_VALUE;
|
---|
1414 | BOOL fResult;
|
---|
1415 |
|
---|
1416 | do
|
---|
1417 | {
|
---|
1418 | DWORD ret = 0;
|
---|
1419 | GUID netGuid;
|
---|
1420 | SP_DEVINFO_DATA DeviceInfoData;
|
---|
1421 | DWORD index = 0;
|
---|
1422 | DWORD size = 0;
|
---|
1423 |
|
---|
1424 | /* initialize the structure size */
|
---|
1425 | DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
|
---|
1426 |
|
---|
1427 | /* copy the net class GUID */
|
---|
1428 | memcpy(&netGuid, &GUID_DEVCLASS_NET, sizeof (GUID_DEVCLASS_NET));
|
---|
1429 |
|
---|
1430 | /* return a device info set contains all installed devices of the Net class */
|
---|
1431 | hDeviceInfo = SetupDiGetClassDevs(&netGuid, NULL, NULL, DIGCF_PRESENT);
|
---|
1432 | if (hDeviceInfo == INVALID_HANDLE_VALUE)
|
---|
1433 | {
|
---|
1434 | logStringW(hModule, L"VBox HostInterfaces: SetupDiGetClassDevs failed (0x%08X)!", GetLastError());
|
---|
1435 | SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
|
---|
1436 | }
|
---|
1437 |
|
---|
1438 | BOOL fFoundDevice = FALSE;
|
---|
1439 |
|
---|
1440 | /* enumerate the driver info list */
|
---|
1441 | while (TRUE)
|
---|
1442 | {
|
---|
1443 | WCHAR *pwszDeviceHwid;
|
---|
1444 |
|
---|
1445 | fResult = SetupDiEnumDeviceInfo(hDeviceInfo, index, &DeviceInfoData);
|
---|
1446 | if (!fResult)
|
---|
1447 | {
|
---|
1448 | if (GetLastError() == ERROR_NO_MORE_ITEMS)
|
---|
1449 | break;
|
---|
1450 | else
|
---|
1451 | {
|
---|
1452 | index++;
|
---|
1453 | continue;
|
---|
1454 | }
|
---|
1455 | }
|
---|
1456 |
|
---|
1457 | /* try to get the hardware ID registry property */
|
---|
1458 | fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo,
|
---|
1459 | &DeviceInfoData,
|
---|
1460 | SPDRP_HARDWAREID,
|
---|
1461 | NULL,
|
---|
1462 | NULL,
|
---|
1463 | 0,
|
---|
1464 | &size);
|
---|
1465 | if (!fResult)
|
---|
1466 | {
|
---|
1467 | if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
---|
1468 | {
|
---|
1469 | index++;
|
---|
1470 | continue;
|
---|
1471 | }
|
---|
1472 |
|
---|
1473 | pwszDeviceHwid = (WCHAR *)malloc(size);
|
---|
1474 | if (pwszDeviceHwid)
|
---|
1475 | {
|
---|
1476 | fResult = SetupDiGetDeviceRegistryProperty(hDeviceInfo,
|
---|
1477 | &DeviceInfoData,
|
---|
1478 | SPDRP_HARDWAREID,
|
---|
1479 | NULL,
|
---|
1480 | (PBYTE)pwszDeviceHwid,
|
---|
1481 | size,
|
---|
1482 | NULL);
|
---|
1483 | if (!fResult)
|
---|
1484 | {
|
---|
1485 | free(pwszDeviceHwid);
|
---|
1486 | pwszDeviceHwid = NULL;
|
---|
1487 | index++;
|
---|
1488 | continue;
|
---|
1489 | }
|
---|
1490 | }
|
---|
1491 | }
|
---|
1492 | else
|
---|
1493 | {
|
---|
1494 | /* something is wrong. This shouldn't have worked with a NULL buffer */
|
---|
1495 | index++;
|
---|
1496 | continue;
|
---|
1497 | }
|
---|
1498 |
|
---|
1499 | for (WCHAR *t = pwszDeviceHwid;
|
---|
1500 | t && *t && t < &pwszDeviceHwid[size / sizeof(WCHAR)];
|
---|
1501 | t += wcslen(t) + 1)
|
---|
1502 | {
|
---|
1503 | if (!_wcsicmp(L"vboxtap", t))
|
---|
1504 | {
|
---|
1505 | /* get the device instance ID */
|
---|
1506 | WCHAR wszDevID[MAX_DEVICE_ID_LEN];
|
---|
1507 | if (CM_Get_Device_IDW(DeviceInfoData.DevInst,
|
---|
1508 | wszDevID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS)
|
---|
1509 | {
|
---|
1510 | /* compare to what we determined before */
|
---|
1511 | if (!wcscmp(wszDevID, wszPnPInstanceId))
|
---|
1512 | {
|
---|
1513 | fFoundDevice = TRUE;
|
---|
1514 | break;
|
---|
1515 | }
|
---|
1516 | }
|
---|
1517 | }
|
---|
1518 | }
|
---|
1519 |
|
---|
1520 | if (pwszDeviceHwid)
|
---|
1521 | {
|
---|
1522 | free(pwszDeviceHwid);
|
---|
1523 | pwszDeviceHwid = NULL;
|
---|
1524 | }
|
---|
1525 |
|
---|
1526 | if (fFoundDevice)
|
---|
1527 | break;
|
---|
1528 |
|
---|
1529 | index++;
|
---|
1530 | }
|
---|
1531 |
|
---|
1532 | if (fFoundDevice)
|
---|
1533 | {
|
---|
1534 | fResult = SetupDiSetSelectedDevice(hDeviceInfo, &DeviceInfoData);
|
---|
1535 | if (!fResult)
|
---|
1536 | {
|
---|
1537 | logStringW(hModule, L"VBox HostInterfaces: SetupDiSetSelectedDevice failed (0x%08X)!", GetLastError());
|
---|
1538 | SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
|
---|
1539 | }
|
---|
1540 |
|
---|
1541 | fResult = SetupDiCallClassInstaller(DIF_REMOVE, hDeviceInfo, &DeviceInfoData);
|
---|
1542 | if (!fResult)
|
---|
1543 | {
|
---|
1544 | logStringW(hModule, L"VBox HostInterfaces: SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)!", GetLastError());
|
---|
1545 | SetErrBreak(L"VBox HostInterfaces: Uninstallation failed!");
|
---|
1546 | }
|
---|
1547 | }
|
---|
1548 | else
|
---|
1549 | SetErrBreak(L"VBox HostInterfaces: Host interface network device not found!");
|
---|
1550 | }
|
---|
1551 | while (0);
|
---|
1552 |
|
---|
1553 | /* clean up the device info set */
|
---|
1554 | if (hDeviceInfo != INVALID_HANDLE_VALUE)
|
---|
1555 | SetupDiDestroyDeviceInfoList(hDeviceInfo);
|
---|
1556 | }
|
---|
1557 | while (0);
|
---|
1558 | return rc;
|
---|
1559 | }
|
---|
1560 |
|
---|
1561 | UINT __stdcall UninstallTAPInstances(MSIHANDLE hModule)
|
---|
1562 | {
|
---|
1563 | static const WCHAR *s_wszNetworkKey = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
|
---|
1564 | HKEY hCtrlNet;
|
---|
1565 |
|
---|
1566 | LONG lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, s_wszNetworkKey, 0, KEY_READ, &hCtrlNet);
|
---|
1567 | if (lStatus == ERROR_SUCCESS)
|
---|
1568 | {
|
---|
1569 | logStringW(hModule, L"VBox HostInterfaces: Enumerating interfaces ...");
|
---|
1570 | for (int i = 0; ; ++i)
|
---|
1571 | {
|
---|
1572 | WCHAR wszNetworkGUID[256] = { 0 };
|
---|
1573 | DWORD dwLen = (DWORD)sizeof(wszNetworkGUID);
|
---|
1574 | lStatus = RegEnumKeyExW(hCtrlNet, i, wszNetworkGUID, &dwLen, NULL, NULL, NULL, NULL);
|
---|
1575 | if (lStatus != ERROR_SUCCESS)
|
---|
1576 | {
|
---|
1577 | switch (lStatus)
|
---|
1578 | {
|
---|
1579 | case ERROR_NO_MORE_ITEMS:
|
---|
1580 | logStringW(hModule, L"VBox HostInterfaces: No interfaces found.");
|
---|
1581 | break;
|
---|
1582 | default:
|
---|
1583 | logStringW(hModule, L"VBox HostInterfaces: Enumeration failed: %ld", lStatus);
|
---|
1584 | break;
|
---|
1585 | }
|
---|
1586 | break;
|
---|
1587 | }
|
---|
1588 |
|
---|
1589 | if (isTAPDevice(wszNetworkGUID))
|
---|
1590 | {
|
---|
1591 | logStringW(hModule, L"VBox HostInterfaces: Removing interface \"%s\" ...", wszNetworkGUID);
|
---|
1592 | removeNetworkInterface(hModule, wszNetworkGUID);
|
---|
1593 | lStatus = RegDeleteKeyW(hCtrlNet, wszNetworkGUID);
|
---|
1594 | }
|
---|
1595 | }
|
---|
1596 | RegCloseKey(hCtrlNet);
|
---|
1597 | logStringW(hModule, L"VBox HostInterfaces: Removing interfaces done.");
|
---|
1598 | }
|
---|
1599 | return ERROR_SUCCESS;
|
---|
1600 | }
|
---|
1601 |
|
---|