Changeset 77804 in vbox for trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg
- Timestamp:
- Mar 20, 2019 8:05:37 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp
r76553 r77804 2580 2580 } 2581 2581 2582 static bool vboxNetCfgWinDetectStaleConnection(PCWSTR pName) 2583 { 2584 HKEY hkeyConnection, hkeyAdapter, hkeyAdapters; 2585 WCHAR wszAdaptersKeyName[] = L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"; 2586 WCHAR wszAdapterSubKeyName[MAX_PATH]; 2587 LSTATUS status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, wszAdaptersKeyName, 0, KEY_ALL_ACCESS, &hkeyAdapters); 2588 if (status != ERROR_SUCCESS) 2589 return false; 2590 2591 bool fFailureImminent = false; 2592 for (DWORD i = 0; !fFailureImminent; ++i) 2593 { 2594 DWORD cbName = MAX_PATH; 2595 status = RegEnumKeyEx(hkeyAdapters, i, wszAdapterSubKeyName, &cbName, NULL, NULL, NULL, NULL); 2596 // if (status == ERROR_NO_MORE_ITEMS) 2597 // break; 2598 if (status != ERROR_SUCCESS) 2599 break; 2600 2601 status = RegOpenKeyEx(hkeyAdapters, wszAdapterSubKeyName, 0, KEY_ALL_ACCESS, &hkeyAdapter); 2602 if (status == ERROR_SUCCESS) 2603 { 2604 status = RegOpenKeyEx(hkeyAdapter, L"Connection", 0, KEY_ALL_ACCESS, &hkeyConnection); 2605 if (status == ERROR_SUCCESS) 2606 { 2607 WCHAR wszName[MAX_PATH]; 2608 cbName = MAX_PATH; 2609 status = RegQueryValueEx(hkeyConnection, L"Name", NULL, NULL, (LPBYTE)wszName, &cbName); 2610 if (status == ERROR_SUCCESS) 2611 if (wcsicmp(wszName, pName) == 0) 2612 fFailureImminent = true; 2613 RegCloseKey(hkeyConnection); 2614 } 2615 RegCloseKey(hkeyAdapter); 2616 } 2617 } 2618 RegCloseKey(hkeyAdapters); 2619 2620 return fFailureImminent; 2621 } 2622 2582 2623 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRenameConnection (LPWSTR pGuid, PCWSTR NewName) 2583 2624 { … … 2586 2627 HRESULT status; 2587 2628 2629 /* 2630 * Before attempting to rename the connection, check if there is a stale 2631 * connection with the same name. We must return ok, so the rest of 2632 * configuration process proceeds normally. 2633 */ 2634 if (vboxNetCfgWinDetectStaleConnection(NewName)) 2635 return S_OK; 2588 2636 /* First try the IShellFolder interface, which was unimplemented 2589 2637 * for the network connections folder before XP. */ … … 2881 2929 } 2882 2930 2883 static HRESULT vboxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, 2931 typedef struct { 2932 BSTR bstrName; 2933 GUID *pGuid; 2934 HRESULT hr; 2935 } RENAMING_CONTEXT; 2936 2937 static BOOL vboxNetCfgWinRenameHostOnlyNetworkInterface(IN INetCfg *pNc, IN INetCfgComponent *pNcc, PVOID pContext) 2938 { 2939 RT_NOREF1(pNc); 2940 RENAMING_CONTEXT *pParams = (RENAMING_CONTEXT *)pContext; 2941 2942 GUID guid; 2943 pParams->hr = pNcc->GetInstanceGuid(&guid); 2944 if ( pParams->hr == S_OK && guid == *pParams->pGuid) 2945 { 2946 /* Located our component, rename it */ 2947 pParams->hr = pNcc->SetDisplayName(pParams->bstrName); 2948 return FALSE; 2949 } 2950 return TRUE; 2951 } 2952 2953 static HRESULT vboxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, IN BSTR bstrDesiredName, 2884 2954 OUT GUID *pGuid, OUT BSTR *lppszName, OUT BSTR *pErrMsg) 2885 2955 { … … 3326 3396 INetCfg *pNetCfg = NULL; 3327 3397 LPWSTR lpszApp = NULL; 3398 3399 RENAMING_CONTEXT context; 3400 context.hr = E_FAIL; 3401 3402 if (pGuid) 3403 { 3404 hrc = CLSIDFromString(pWCfgGuidString, (LPCLSID)pGuid); 3405 if (FAILED(hrc)) 3406 NonStandardLogFlow(("CLSIDFromString failed, hrc (0x%x)\n", hrc)); 3407 } 3408 3409 hr = VBoxNetCfgWinQueryINetCfg(&pNetCfg, TRUE, L"VirtualBox Host-Only Creation", 3410 30 * 1000, /* on Vista we often get 6to4svc.dll holding the lock, wait for 30 sec. */ 3411 /** @todo special handling for 6to4svc.dll ???, i.e. several retrieves */ 3412 &lpszApp); 3413 if (hr == S_OK) 3414 { 3415 if (SysStringLen(bstrDesiredName) != 0) 3416 { 3417 /* Rename only if the desired name has been provided */ 3418 context.bstrName = bstrDesiredName; 3419 context.pGuid = pGuid; 3420 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg, 3421 &GUID_DEVCLASS_NET, 3422 vboxNetCfgWinRenameHostOnlyNetworkInterface, 3423 &context); 3424 } 3425 if (SUCCEEDED(hr)) 3426 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg, 3427 &GUID_DEVCLASS_NETSERVICE, 3428 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority, 3429 pGuid); 3430 if (SUCCEEDED(hr)) 3431 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg, 3432 &GUID_DEVCLASS_NETTRANS, 3433 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority, 3434 pGuid); 3435 if (SUCCEEDED(hr)) 3436 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg, 3437 &GUID_DEVCLASS_NETCLIENT, 3438 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority, 3439 pGuid); 3440 if (SUCCEEDED(hr)) 3441 { 3442 hr = pNetCfg->Apply(); 3443 } 3444 else 3445 NonStandardLogFlow(("Enumeration failed, hr 0x%x\n", hr)); 3446 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 3447 } 3448 else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszApp) 3449 { 3450 NonStandardLogFlow(("Application %ws is holding the lock, failed\n", lpszApp)); 3451 CoTaskMemFree(lpszApp); 3452 } 3453 else 3454 NonStandardLogFlow(("VBoxNetCfgWinQueryINetCfg failed, hr 0x%x\n", hr)); 3455 3328 3456 #ifndef VBOXNETCFG_DELAYEDRENAME 3457 if (SUCCEEDED(hr) && SUCCEEDED(context.hr)) 3458 { 3459 /* The device has been successfully renamed, replace the name now. */ 3460 wcscpy_s(DevName, RT_ELEMENTS(DevName), bstrDesiredName); 3461 } 3462 3329 3463 WCHAR ConnectionName[128]; 3330 3464 ULONG cbName = sizeof(ConnectionName); … … 3343 3477 } 3344 3478 } 3345 3346 if (pGuid)3347 {3348 hrc = CLSIDFromString(pWCfgGuidString, (LPCLSID)pGuid);3349 if (FAILED(hrc))3350 NonStandardLogFlow(("CLSIDFromString failed, hrc (0x%x)\n", hrc));3351 }3352 3353 hr = VBoxNetCfgWinQueryINetCfg(&pNetCfg, TRUE, L"VirtualBox Host-Only Creation",3354 30 * 1000, /* on Vista we often get 6to4svc.dll holding the lock, wait for 30 sec. */3355 /** @todo special handling for 6to4svc.dll ???, i.e. several retrieves */3356 &lpszApp);3357 if (hr == S_OK)3358 {3359 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,3360 &GUID_DEVCLASS_NETSERVICE,3361 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,3362 pGuid);3363 if (SUCCEEDED(hr))3364 {3365 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,3366 &GUID_DEVCLASS_NETTRANS,3367 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,3368 pGuid);3369 if (SUCCEEDED(hr))3370 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,3371 &GUID_DEVCLASS_NETCLIENT,3372 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,3373 pGuid);3374 }3375 3376 if (SUCCEEDED(hr))3377 {3378 hr = pNetCfg->Apply();3379 }3380 else3381 NonStandardLogFlow(("Enumeration failed, hr 0x%x\n", hr));3382 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);3383 }3384 else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszApp)3385 {3386 NonStandardLogFlow(("Application %ws is holding the lock, failed\n", lpszApp));3387 CoTaskMemFree(lpszApp);3388 }3389 else3390 NonStandardLogFlow(("VBoxNetCfgWinQueryINetCfg failed, hr 0x%x\n", hr));3391 3479 } 3392 3480 … … 3397 3485 } 3398 3486 3399 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, 3487 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, IN BSTR pwsDesiredName, 3400 3488 OUT GUID *pGuid, OUT BSTR *lppszName, OUT BSTR *pErrMsg) 3401 3489 { 3402 HRESULT hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, p Guid, lppszName, pErrMsg);3490 HRESULT hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, pwsDesiredName, pGuid, lppszName, pErrMsg); 3403 3491 if (hrc == E_ABORT) 3404 3492 { … … 3412 3500 * See @bugref{7973} for details. 3413 3501 */ 3414 hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, p Guid, lppszName, pErrMsg);3502 hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, pwsDesiredName, pGuid, lppszName, pErrMsg); 3415 3503 if (hrc == E_ABORT) 3416 3504 { … … 3435 3523 Sleep(1000); 3436 3524 CloseServiceHandle(hService); 3437 hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, p Guid, lppszName, pErrMsg);3525 hrc = vboxNetCfgWinCreateHostOnlyNetworkInterface(pInfPath, bIsInfPathFile, pwsDesiredName, pGuid, lppszName, pErrMsg); 3438 3526 } 3439 3527 else
Note:
See TracChangeset
for help on using the changeset viewer.