1 | /* $Id: NetFltInstall.cpp 21343 2009-07-07 15:30:08Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * NetFltInstall - VBoxNetFlt installer command line tool
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include <vbox/WinNetConfig.h>
|
---|
23 | #include <devguid.h>
|
---|
24 | #include <stdio.h>
|
---|
25 |
|
---|
26 | #define NETFLT_ID L"sun_VBoxNetFlt"
|
---|
27 | #define VBOX_NETCFG_APP_NAME L"NetFltInstall"
|
---|
28 | #define VBOX_NETFLT_PT_INF L".\\VBoxNetFlt.inf"
|
---|
29 | #define VBOX_NETFLT_MP_INF L".\\VBoxNetFlt_m.inf"
|
---|
30 | #define VBOX_NETFLT_RETRIES 10
|
---|
31 |
|
---|
32 |
|
---|
33 | static VOID winNetCfgLogger (LPCWSTR szString)
|
---|
34 | {
|
---|
35 | wprintf(L"%s", szString);
|
---|
36 | }
|
---|
37 |
|
---|
38 | static int InstallNetFlt()
|
---|
39 | {
|
---|
40 | WCHAR PtInf[MAX_PATH];
|
---|
41 | WCHAR MpInf[MAX_PATH];
|
---|
42 | INetCfg *pnc;
|
---|
43 | LPWSTR lpszLockedBy = NULL;
|
---|
44 | int r = 1;
|
---|
45 |
|
---|
46 | VBoxNetCfgWinSetLogging(winNetCfgLogger);
|
---|
47 |
|
---|
48 | HRESULT hr = CoInitialize(NULL);
|
---|
49 | if(hr == S_OK)
|
---|
50 | {
|
---|
51 | int i = 0;
|
---|
52 | do
|
---|
53 | {
|
---|
54 | hr = VBoxNetCfgWinQueryINetCfg(TRUE, VBOX_NETCFG_APP_NAME, &pnc, &lpszLockedBy);
|
---|
55 | if(hr == S_OK)
|
---|
56 | {
|
---|
57 | DWORD WinEr;
|
---|
58 | GetFullPathNameW(VBOX_NETFLT_PT_INF, sizeof(PtInf)/sizeof(PtInf[0]), PtInf, NULL);
|
---|
59 | WinEr = GetLastError();
|
---|
60 | if(WinEr == ERROR_SUCCESS)
|
---|
61 | {
|
---|
62 | GetFullPathNameW(VBOX_NETFLT_MP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf, NULL);
|
---|
63 | WinEr = GetLastError();
|
---|
64 | if(WinEr == ERROR_SUCCESS)
|
---|
65 | {
|
---|
66 | LPCWSTR aInfs[] = {PtInf, MpInf};
|
---|
67 | hr = VBoxNetCfgWinNetFltInstall(pnc, aInfs, 2);
|
---|
68 | if(hr == S_OK)
|
---|
69 | {
|
---|
70 | wprintf(L"installed successfully\n");
|
---|
71 | r = 0;
|
---|
72 | }
|
---|
73 | else
|
---|
74 | {
|
---|
75 | wprintf(L"error installing VBoxNetFlt (0x%x)\n", hr);
|
---|
76 | }
|
---|
77 | }
|
---|
78 | else
|
---|
79 | {
|
---|
80 | hr = HRESULT_FROM_WIN32(WinEr);
|
---|
81 | wprintf(L"error getting full inf path for VBoxNetFlt_m.inf (0x%x)\n", hr);
|
---|
82 | }
|
---|
83 | }
|
---|
84 | else
|
---|
85 | {
|
---|
86 | hr = HRESULT_FROM_WIN32(WinEr);
|
---|
87 | wprintf(L"error getting full inf path for VBoxNetFlt.inf (0x%x)\n", hr);
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
|
---|
92 | break;
|
---|
93 | }
|
---|
94 | else if(hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
|
---|
95 | {
|
---|
96 | if(i < VBOX_NETFLT_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
|
---|
97 | {
|
---|
98 | wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETFLT_RETRIES);
|
---|
99 | CoTaskMemFree(lpszLockedBy);
|
---|
100 | }
|
---|
101 | else
|
---|
102 | {
|
---|
103 | wprintf(L"Error: write lock is owned by another application (%s), close the application and retry installing\n", lpszLockedBy);
|
---|
104 | r = 1;
|
---|
105 | CoTaskMemFree(lpszLockedBy);
|
---|
106 | break;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | else
|
---|
110 | {
|
---|
111 | wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
|
---|
112 | r = 1;
|
---|
113 | break;
|
---|
114 | }
|
---|
115 | } while(true);
|
---|
116 |
|
---|
117 | CoUninitialize();
|
---|
118 | }
|
---|
119 | else
|
---|
120 | {
|
---|
121 | wprintf(L"Error initializing COM (0x%x)\n", hr);
|
---|
122 | r = 1;
|
---|
123 | }
|
---|
124 |
|
---|
125 | VBoxNetCfgWinSetLogging(NULL);
|
---|
126 |
|
---|
127 | return r;
|
---|
128 | }
|
---|
129 |
|
---|
130 | int __cdecl main(int argc, char **argv)
|
---|
131 | {
|
---|
132 | return InstallNetFlt();
|
---|
133 | }
|
---|