VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/VBoxNetFlt/win/NetFltInstall.cpp@ 25385

Last change on this file since 25385 was 25385, checked in by vboxsync, 15 years ago

2d: basics for FBO (for linear stretching) suport, more impl for guest-mapped PBO, code cleaning, bug-fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* $Id: NetFltInstall.cpp 25385 2009-12-15 09:43:23Z 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
33static VOID winNetCfgLogger (LPCWSTR szString)
34{
35 wprintf(L"%s", szString);
36}
37
38/** Wrapper aroung GetfullPathNameW that will try an alternative INF location.
39 *
40 * The default location is the current directory. If not found there, the
41 * alternative locatoin is the executable directory. If not found there either,
42 * the first alternative is present to the caller.
43 */
44static DWORD MyGetfullPathNameW(LPCWSTR pwszName, size_t cchFull, LPWSTR pwszFull)
45{
46#ifdef DEBUG_bird /** @todo make this default behavior after 3.1. */
47 LPWSTR pwszFilePart;
48 DWORD dwSize = GetFullPathNameW(pwszName, cchFull, pwszFull, &pwszFilePart);
49 if(dwSize <= 0)
50 return dwSize;
51
52 /* if it doesn't exist, see if the file exists in the same directory as the executable. */
53 if (GetFileAttributesW(pwszFull) == INVALID_FILE_ATTRIBUTES)
54 {
55 WCHAR wsz[512];
56 DWORD cch = GetModuleFileNameW(GetModuleHandle(NULL), &wsz[0], sizeof(wsz) / sizeof(wsz[0]));
57 if(cch > 0)
58 {
59 while(cch > 0 && wsz[cch - 1] != '/' && wsz[cch - 1] != '\\' && wsz[cch - 1] != ':')
60 cch--;
61 unsigned i = 0;
62 while(cch < sizeof(wsz) / sizeof(wsz[0]))
63 {
64 wsz[cch] = pwszFilePart[i++];
65 if(!wsz[cch])
66 {
67 dwSize = GetFullPathNameW(wsz, cchFull, pwszFull, NULL);
68 if( dwSize > 0
69 && GetFileAttributesW(pwszFull) != INVALID_FILE_ATTRIBUTES)
70 return dwSize;
71 break;
72 }
73 cch++;
74 }
75 }
76 }
77
78 /* fallback */
79#endif
80 return GetFullPathNameW(pwszName, cchFull, pwszFull, NULL);
81}
82
83static int InstallNetFlt()
84{
85 WCHAR PtInf[MAX_PATH];
86 WCHAR MpInf[MAX_PATH];
87 INetCfg *pnc;
88 LPWSTR lpszLockedBy = NULL;
89 int r = 1;
90
91 VBoxNetCfgWinSetLogging(winNetCfgLogger);
92
93 HRESULT hr = CoInitialize(NULL);
94 if(hr == S_OK)
95 {
96#if 0
97 int i = 0;
98 do
99 {
100 hr = VBoxNetCfgWinQueryINetCfg(TRUE, VBOX_NETCFG_APP_NAME, &pnc, &lpszLockedBy);
101 if(hr == S_OK)
102 {
103 DWORD dwSize;
104 dwSize = MyGetfullPathNameW(VBOX_NETFLT_PT_INF, sizeof(PtInf)/sizeof(PtInf[0]), PtInf);
105 if(dwSize > 0)
106 {
107 /** @todo add size check for (sizeof(PtInf)/sizeof(PtInf[0])) == dwSize (string length in sizeof(PtInf[0])) */
108
109 dwSize = MyGetfullPathNameW(VBOX_NETFLT_MP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf);
110 if(dwSize > 0)
111 {
112 /** @todo add size check for (sizeof(MpInf)/sizeof(MpInf[0])) == dwSize (string length in sizeof(MpInf[0])) */
113
114 LPCWSTR aInfs[] = {PtInf, MpInf};
115 hr = VBoxNetCfgWinNetFltInstall(pnc, aInfs, 2);
116 if(hr == S_OK)
117 {
118 wprintf(L"installed successfully\n");
119 r = 0;
120 }
121 else
122 {
123 wprintf(L"error installing VBoxNetFlt (0x%x)\n", hr);
124 }
125 }
126 else
127 {
128 hr = HRESULT_FROM_WIN32(GetLastError());
129 wprintf(L"error getting full inf path for VBoxNetFlt_m.inf (0x%x)\n", hr);
130 }
131 }
132 else
133 {
134 hr = HRESULT_FROM_WIN32(GetLastError());
135 wprintf(L"error getting full inf path for VBoxNetFlt.inf (0x%x)\n", hr);
136 }
137
138
139 VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
140 break;
141 }
142 else if(hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
143 {
144 if(i < VBOX_NETFLT_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
145 {
146 wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETFLT_RETRIES);
147 CoTaskMemFree(lpszLockedBy);
148 }
149 else
150 {
151 wprintf(L"Error: write lock is owned by another application (%s), close the application and retry installing\n", lpszLockedBy);
152 r = 1;
153 CoTaskMemFree(lpszLockedBy);
154 break;
155 }
156 }
157 else
158 {
159 wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
160 r = 1;
161 break;
162 }
163 } while(true);
164#endif
165 VBoxNetCfgWinEnumUpperBindings ();
166
167 CoUninitialize();
168 }
169 else
170 {
171 wprintf(L"Error initializing COM (0x%x)\n", hr);
172 r = 1;
173 }
174
175 VBoxNetCfgWinSetLogging(NULL);
176
177 return r;
178}
179
180int __cdecl main(int argc, char **argv)
181{
182 return InstallNetFlt();
183}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette