VBoxNetCfg.cpp revision 46898cd9e04d40d7306ad1f6e957648072a70a22
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* $Id$ */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** @file
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * VBoxNetCfg.cpp - Network Configuration API.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/*
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2011-2012 Oracle Corporation
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * available from http://www.virtualbox.org. This file is free software;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * you can redistribute it and/or modify it under the terms of the GNU
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * General Public License (GPL) as published by the Free Software
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include "VBox/VBoxNetCfg-win.h"
2fa05a4e777b070ba9bf01e3dd46434c99cd06a3vboxsync#include "VBox/VBoxDrvCfg-win.h"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define _WIN32_DCOM
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <iphlpapi.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <devguid.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <stdio.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <regstr.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <shlobj.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <cfgmgr32.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <tchar.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <objbase.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <crtdbg.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <stdlib.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <string.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <Wbemidl.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#include <comdef.h>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3581dfd579fa647c95528b7f7d24740111a36903vboxsync#ifndef Assert /** @todo r=bird: where would this be defined? */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# ifdef DEBUG
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# define Assert(_expr) assert(_expr)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# define Assert(_expr) do{ }while (0)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync//# endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define Assert _ASSERT
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync# define AssertMsg(expr, msg) do{}while (0)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic LOG_ROUTINE g_Logger = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic VOID DoLogging(LPCSTR szString, ...);
3581dfd579fa647c95528b7f7d24740111a36903vboxsync#define NonStandardLog DoLogging
3581dfd579fa647c95528b7f7d24740111a36903vboxsync#define NonStandardLogFlow(x) DoLogging x
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3581dfd579fa647c95528b7f7d24740111a36903vboxsync#define DbgLog /** @todo r=bird: What does this do? */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3581dfd579fa647c95528b7f7d24740111a36903vboxsync#define VBOX_NETCFG_LOCK_TIME_OUT 5000 /** @todo r=bird: What does this do? */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT vboxNetCfgWinINetCfgLock(IN INetCfg *pNetCfg,
d97357e2036109245c83ba553d0290212e28ea40vboxsync IN LPCWSTR pszwClientDescription,
d97357e2036109245c83ba553d0290212e28ea40vboxsync IN DWORD cmsTimeout,
d97357e2036109245c83ba553d0290212e28ea40vboxsync OUT LPWSTR *ppszwClientDescription)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync INetCfgLock *pLock;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pNetCfg->QueryInterface(IID_INetCfgLock, (PVOID*)&pLock);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("QueryInterface failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pLock->AcquireWriteLock(cmsTimeout, pszwClientDescription, ppszwClientDescription);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hr == S_FALSE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Write lock busy\n"));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync else if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("AcquireWriteLock failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pLock->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT vboxNetCfgWinINetCfgUnlock(IN INetCfg *pNetCfg)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync INetCfgLock *pLock;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pNetCfg->QueryInterface(IID_INetCfgLock, (PVOID*)&pLock);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("QueryInterface failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pLock->ReleaseWriteLock();
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("ReleaseWriteLock failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pLock->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinQueryINetCfg(OUT INetCfg **ppNetCfg,
d97357e2036109245c83ba553d0290212e28ea40vboxsync IN BOOL fGetWriteLock,
d97357e2036109245c83ba553d0290212e28ea40vboxsync IN LPCWSTR pszwClientDescription,
d97357e2036109245c83ba553d0290212e28ea40vboxsync IN DWORD cmsTimeout,
d97357e2036109245c83ba553d0290212e28ea40vboxsync OUT LPWSTR *ppszwClientDescription)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync INetCfg *pNetCfg;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, IID_INetCfg, (PVOID*)&pNetCfg);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("CoCreateInstance failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (fGetWriteLock)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = vboxNetCfgWinINetCfgLock(pNetCfg, pszwClientDescription, cmsTimeout, ppszwClientDescription);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hr == S_FALSE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Write lock is busy\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = NETCFG_E_NO_WRITE_LOCK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pNetCfg->Initialize(NULL);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *ppNetCfg = pNetCfg;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Initialize failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pNetCfg->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinReleaseINetCfg(IN INetCfg *pNetCfg, IN BOOL fHasWriteLock)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
89785e233a2828c846caf26ea6e66b1641fc1c47vboxsync if (!pNetCfg) /* If network config has been released already, just bail out. */
4ce3d4b5c12636b70579aed52e55fa8b4f49bff2vboxsync {
4ce3d4b5c12636b70579aed52e55fa8b4f49bff2vboxsync NonStandardLogFlow(("Warning: No network config given but write lock is set to TRUE\n"));
89785e233a2828c846caf26ea6e66b1641fc1c47vboxsync return S_OK;
4ce3d4b5c12636b70579aed52e55fa8b4f49bff2vboxsync }
89785e233a2828c846caf26ea6e66b1641fc1c47vboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pNetCfg->Uninitialize();
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Uninitialize failed, hr (0x%x)\n", hr));
4ce3d4b5c12636b70579aed52e55fa8b4f49bff2vboxsync /* Try to release the write lock below. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (fHasWriteLock)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
4ce3d4b5c12636b70579aed52e55fa8b4f49bff2vboxsync HRESULT hr2 = vboxNetCfgWinINetCfgUnlock(pNetCfg);
4ce3d4b5c12636b70579aed52e55fa8b4f49bff2vboxsync if (FAILED(hr2))
4ce3d4b5c12636b70579aed52e55fa8b4f49bff2vboxsync NonStandardLogFlow(("vboxNetCfgWinINetCfgUnlock failed, hr (0x%x)\n", hr2));
4ce3d4b5c12636b70579aed52e55fa8b4f49bff2vboxsync if (SUCCEEDED(hr))
4ce3d4b5c12636b70579aed52e55fa8b4f49bff2vboxsync hr = hr2;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pNetCfg->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncstatic HRESULT vboxNetCfgWinGetComponentByGuidEnum(IEnumNetCfgComponent *pEnumNcc,
d97357e2036109245c83ba553d0290212e28ea40vboxsync IN const GUID *pGuid,
d97357e2036109245c83ba553d0290212e28ea40vboxsync OUT INetCfgComponent **ppNcc)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pEnumNcc->Reset();
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Reset failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync INetCfgComponent *pNcc;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync while ((hr = pEnumNcc->Next(1, &pNcc, NULL)) == S_OK)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG uComponentStatus;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pNcc->GetDeviceStatus(&uComponentStatus);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (uComponentStatus == 0)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync GUID NccGuid;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pNcc->GetInstanceGuid(&NccGuid);
d97357e2036109245c83ba553d0290212e28ea40vboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (NccGuid == *pGuid)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* found the needed device */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *ppNcc = pNcc;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("GetInstanceGuid failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pNcc->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGetComponentByGuid(IN INetCfg *pNc,
d97357e2036109245c83ba553d0290212e28ea40vboxsync IN const GUID *pguidClass,
d97357e2036109245c83ba553d0290212e28ea40vboxsync IN const GUID * pComponentGuid,
d97357e2036109245c83ba553d0290212e28ea40vboxsync OUT INetCfgComponent **ppncc)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync IEnumNetCfgComponent *pEnumNcc;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pNc->EnumComponents(pguidClass, &pEnumNcc);
d97357e2036109245c83ba553d0290212e28ea40vboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = vboxNetCfgWinGetComponentByGuidEnum(pEnumNcc, pComponentGuid, ppncc);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hr == S_FALSE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Component not found\n"));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync else if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("vboxNetCfgWinGetComponentByGuidEnum failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pEnumNcc->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("EnumComponents failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT vboxNetCfgWinQueryInstaller(IN INetCfg *pNetCfg, IN const GUID *pguidClass, INetCfgClassSetup **ppSetup)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pNetCfg->QueryNetCfgClass(pguidClass, IID_INetCfgClassSetup, (void**)ppSetup);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("QueryNetCfgClass failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinInstallComponent(IN INetCfg *pNetCfg, IN LPCWSTR pszwComponentId, IN const GUID *pguidClass,
d97357e2036109245c83ba553d0290212e28ea40vboxsync OUT INetCfgComponent **ppComponent)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync INetCfgClassSetup *pSetup;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = vboxNetCfgWinQueryInstaller(pNetCfg, pguidClass, &pSetup);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("vboxNetCfgWinQueryInstaller failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync OBO_TOKEN Token;
d97357e2036109245c83ba553d0290212e28ea40vboxsync ZeroMemory(&Token, sizeof (Token));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Token.Type = OBO_USER;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSetup->Install(pszwComponentId, &Token,
d97357e2036109245c83ba553d0290212e28ea40vboxsync 0, /* IN DWORD dwSetupFlags */
d97357e2036109245c83ba553d0290212e28ea40vboxsync 0, /* IN DWORD dwUpgradeFromBuildNo */
d97357e2036109245c83ba553d0290212e28ea40vboxsync NULL, /* IN LPCWSTR pszwAnswerFile */
d97357e2036109245c83ba553d0290212e28ea40vboxsync NULL, /* IN LPCWSTR pszwAnswerSections */
d97357e2036109245c83ba553d0290212e28ea40vboxsync ppComponent);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* ignore the apply failure */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT tmpHr = pNetCfg->Apply();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Assert(tmpHr == S_OK);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (tmpHr != S_OK)
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Apply failed, hr (0x%x)\n", tmpHr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Install failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pSetup->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsyncstatic HRESULT vboxNetCfgWinInstallInfAndComponent(IN INetCfg *pNetCfg, IN LPCWSTR pszwComponentId, IN const GUID *pguidClass,
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync IN LPCWSTR const *apInfPaths, IN UINT cInfPaths,
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync OUT INetCfgComponent **ppComponent)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = S_OK;
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync UINT cFilesProcessed = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Installing %u INF files ...\n", cInfPaths));
d97357e2036109245c83ba553d0290212e28ea40vboxsync
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync for (; cFilesProcessed < cInfPaths; cFilesProcessed++)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync NonStandardLogFlow(("Installing INF file \"%ws\" ...\n", apInfPaths[cFilesProcessed]));
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync hr = VBoxDrvCfgInfInstall(apInfPaths[cFilesProcessed]);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("VBoxNetCfgWinInfInstall failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = VBoxNetCfgWinInstallComponent(pNetCfg, pszwComponentId, pguidClass, ppComponent);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("VBoxNetCfgWinInstallComponent failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync NonStandardLogFlow(("Installation failed, rolling back installation set ...\n"));
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync do
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync {
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync HRESULT hr2 = VBoxDrvCfgInfUninstall(apInfPaths[cFilesProcessed], 0);
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync if (FAILED(hr2))
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync NonStandardLogFlow(("VBoxDrvCfgInfUninstall failed, hr (0x%x)\n", hr2));
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync /* Keep going. */
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync if (!cFilesProcessed)
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync break;
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync } while (cFilesProcessed--);
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync NonStandardLogFlow(("Rollback complete\n"));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinUninstallComponent(IN INetCfg *pNetCfg, IN INetCfgComponent *pComponent)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GUID GuidClass;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pComponent->GetClassGuid(&GuidClass);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("GetClassGuid failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync INetCfgClassSetup *pSetup = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = vboxNetCfgWinQueryInstaller(pNetCfg, &GuidClass, &pSetup);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("vboxNetCfgWinQueryInstaller failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync OBO_TOKEN Token;
d97357e2036109245c83ba553d0290212e28ea40vboxsync ZeroMemory(&Token, sizeof(Token));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Token.Type = OBO_USER;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSetup->DeInstall(pComponent, &Token, NULL /* OUT LPWSTR *pmszwRefs */);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfg->Apply();
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Apply failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("DeInstall failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (pSetup)
d97357e2036109245c83ba553d0290212e28ea40vboxsync pSetup->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsynctypedef BOOL (*VBOXNETCFGWIN_NETCFGENUM_CALLBACK) (IN INetCfg *pNetCfg, IN INetCfgComponent *pNetCfgComponent, PVOID pContext);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncstatic HRESULT vboxNetCfgWinEnumNetCfgComponents(IN INetCfg *pNetCfg,
d97357e2036109245c83ba553d0290212e28ea40vboxsync IN const GUID *pguidClass,
d97357e2036109245c83ba553d0290212e28ea40vboxsync VBOXNETCFGWIN_NETCFGENUM_CALLBACK callback,
d97357e2036109245c83ba553d0290212e28ea40vboxsync PVOID pContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync IEnumNetCfgComponent *pEnumComponent;
d97357e2036109245c83ba553d0290212e28ea40vboxsync HRESULT hr = pNetCfg->EnumComponents(pguidClass, &pEnumComponent);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync INetCfgComponent *pNetCfgComponent;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pEnumComponent->Reset();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync do
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pEnumComponent->Next(1, &pNetCfgComponent, NULL);
a2fa8d93a2e59ba1413354f35db5efa61062971cvboxsync if (hr == S_OK)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// ULONG uComponentStatus;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// hr = pNcc->GetDeviceStatus(&uComponentStatus);
d97357e2036109245c83ba553d0290212e28ea40vboxsync// if (SUCCEEDED(hr))
d97357e2036109245c83ba553d0290212e28ea40vboxsync BOOL fResult = FALSE;
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (pNetCfgComponent)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (pContext)
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = callback(pNetCfg, pNetCfgComponent, pContext);
d97357e2036109245c83ba553d0290212e28ea40vboxsync pNetCfgComponent->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
d97357e2036109245c83ba553d0290212e28ea40vboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (hr == S_FALSE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Next failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync } while (true);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pEnumComponent->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync/*
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync * Forward declarations of functions used in vboxNetCfgWinRemoveAllNetDevicesOfIdCallback.
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync */
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGenHostonlyConnectionName(PCWSTR DevName, WCHAR *pBuf, PULONG pcbBuf);
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRenameConnection(LPWSTR pGuid, PCWSTR NewName);
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic BOOL vboxNetCfgWinRemoveAllNetDevicesOfIdCallback(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SP_REMOVEDEVICE_PARAMS rmdParams;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync memset(&rmdParams, 0, sizeof(SP_REMOVEDEVICE_PARAMS));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync rmdParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync rmdParams.ClassInstallHeader.InstallFunction = DIF_REMOVE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync rmdParams.Scope = DI_REMOVEDEVICE_GLOBAL;
d97357e2036109245c83ba553d0290212e28ea40vboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if (SetupDiSetClassInstallParams(hDevInfo,pDev,
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync &rmdParams.ClassInstallHeader, sizeof(rmdParams)))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if (SetupDiSetSelectedDevice(hDevInfo, pDev))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync /* Figure out NetCfgInstanceId. */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync HKEY hKey = SetupDiOpenDevRegKey(hDevInfo,
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync pDev,
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync DICS_FLAG_GLOBAL,
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync 0,
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync DIREG_DRV,
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync KEY_READ);
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if (hKey == INVALID_HANDLE_VALUE)
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: SetupDiOpenDevRegKey failed with error %ld\n",
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync GetLastError()));
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync }
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync else
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync WCHAR wszCfgGuidString[50] = { L'' };
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync DWORD cbSize = sizeof(wszCfgGuidString);
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync DWORD dwValueType;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync DWORD ret = RegQueryValueExW(hKey, L"NetCfgInstanceId", NULL,
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync &dwValueType, (LPBYTE)wszCfgGuidString, &cbSize);
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync if (ret == ERROR_SUCCESS)
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: Processing device ID \"%S\"\n",
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync wszCfgGuidString));
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync /* Figure out device name. */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync WCHAR wszDevName[256], wszTempName[256];
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync ULONG cbName = sizeof(wszTempName);
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync if (SetupDiGetDeviceRegistryPropertyW(hDevInfo, pDev,
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync SPDRP_FRIENDLYNAME, /* IN DWORD Property,*/
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NULL, /* OUT PDWORD PropertyRegDataType, OPTIONAL*/
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync (PBYTE)wszDevName, /* OUT PBYTE PropertyBuffer,*/
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync sizeof(wszDevName), /* IN DWORD PropertyBufferSize,*/
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NULL /* OUT PDWORD RequiredSize OPTIONAL*/))
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync {
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync /*
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync * Rename the connection before removing the device. This will
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync * hopefully prevent an error when we will be attempting
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync * to rename a newly created connection (see @bugref{6740}).
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName(wszDevName, wszTempName, &cbName);
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync wcscat_s(wszTempName, sizeof(wszTempName), L" removed");
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync if (SUCCEEDED(hr))
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync hr = VBoxNetCfgWinRenameConnection(wszCfgGuidString, wszTempName);
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync //NonStandardLogFlow(("VBoxNetCfgWinRenameConnection(%S,%S) => 0x%x\n", pWCfgGuidString, TempName, hr_tmp));
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync }
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync else
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: Failed to get friendly name for device \"%S\"\n",
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync wszCfgGuidString));
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync }
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync }
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync else
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: Querying instance ID failed with %d\n",
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync ret));
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync }
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync RegCloseKey(hKey);
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync }
eabf4e0a489160ac121a73dab0222571ae262dd3vboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if (SetupDiCallClassInstaller(DIF_REMOVE, hDevInfo, pDev))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SP_DEVINSTALL_PARAMS devParams;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync memset(&devParams, 0, sizeof(SP_DEVINSTALL_PARAMS));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync devParams.cbSize = sizeof(devParams);
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if (SetupDiGetDeviceInstallParams(hDevInfo, pDev, &devParams))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if ( (devParams.Flags & DI_NEEDRESTART)
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync || (devParams.Flags & DI_NEEDREBOOT))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLog(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: A reboot is required\n"));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync else
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: SetupDiGetDeviceInstallParams failed with %ld\n",
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: SetupDiCallClassInstaller failed with %ld\n",
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: SetupDiSetSelectedDevice failed with %ld\n",
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("vboxNetCfgWinRemoveAllNetDevicesOfIdCallback: SetupDiSetClassInstallParams failed with %ld\n",
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync /* Continue enumeration. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return TRUE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsynctypedef struct VBOXNECTFGWINPROPCHANGE
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync{
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync VBOXNECTFGWINPROPCHANGE_TYPE enmPcType;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync HRESULT hr;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync} VBOXNECTFGWINPROPCHANGE ,*PVBOXNECTFGWINPROPCHANGE;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsyncstatic BOOL vboxNetCfgWinPropChangeAllNetDevicesOfIdCallback(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext)
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync{
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync PVBOXNECTFGWINPROPCHANGE pPc = (PVBOXNECTFGWINPROPCHANGE)pContext;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync SP_PROPCHANGE_PARAMS PcParams;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync memset (&PcParams, 0, sizeof (PcParams));
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync PcParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync PcParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync PcParams.Scope = DICS_FLAG_GLOBAL;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync switch(pPc->enmPcType)
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync {
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync case VBOXNECTFGWINPROPCHANGE_TYPE_DISABLE:
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync PcParams.StateChange = DICS_DISABLE;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync break;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync case VBOXNECTFGWINPROPCHANGE_TYPE_ENABLE:
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync PcParams.StateChange = DICS_ENABLE;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync break;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync default:
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("vboxNetCfgWinPropChangeAllNetDevicesOfIdCallback: Unexpected prop change type: %d\n", pPc->enmPcType));
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync pPc->hr = E_INVALIDARG;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync return FALSE;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync }
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if (SetupDiSetClassInstallParams(hDevInfo, pDev, &PcParams.ClassInstallHeader, sizeof(PcParams)))
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync {
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync if (SetupDiSetSelectedDevice(hDevInfo, pDev))
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync {
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync if (SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevInfo, pDev))
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync {
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync SP_DEVINSTALL_PARAMS devParams;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync devParams.cbSize = sizeof(devParams);
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync if (SetupDiGetDeviceInstallParams(hDevInfo,pDev,&devParams))
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if ( (devParams.Flags & DI_NEEDRESTART)
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync || (devParams.Flags & DI_NEEDREBOOT))
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLog(("vboxNetCfgWinPropChangeAllNetDevicesOfIdCallback: A reboot is required\n"));
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync }
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync }
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync else
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("vboxNetCfgWinPropChangeAllNetDevicesOfIdCallback: SetupDiGetDeviceInstallParams failed with %ld\n",
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync GetLastError()));
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync }
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync else
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("vboxNetCfgWinPropChangeAllNetDevicesOfIdCallback: SetupDiCallClassInstaller failed with %ld\n",
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync GetLastError()));
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync }
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync else
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("SetupDiSetSelectedDevice failed with %ld\n", GetLastError()));
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync }
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync else
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("SetupDiSetClassInstallParams failed with %ld\n", GetLastError()));
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync /* Continue enumeration. */
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync return TRUE;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync}
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef BOOL (*VBOXNETCFGWIN_NETENUM_CALLBACK) (HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext);
468190b22aeddd68559df8a742aef64ee8974d0bvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinEnumNetDevices(LPCWSTR pwszPnPId,
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync VBOXNETCFGWIN_NETENUM_CALLBACK callback, PVOID pContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: Searching for: %S\n", pwszPnPId));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync HRESULT hr;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync HDEVINFO hDevInfo = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET,
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NULL, /* IN PCTSTR Enumerator, OPTIONAL */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NULL, /* IN HWND hwndParent, OPTIONAL */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync DIGCF_PRESENT, /* IN DWORD Flags,*/
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NULL, /* IN HDEVINFO DeviceInfoSet, OPTIONAL */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NULL, /* IN PCTSTR MachineName, OPTIONAL */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NULL /* IN PVOID Reserved */);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hDevInfo != INVALID_HANDLE_VALUE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync DWORD winEr;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync DWORD dwDevId = 0;
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync size_t cPnPId = wcslen(pwszPnPId);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync PBYTE pBuffer = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync for (;;)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync SP_DEVINFO_DATA Dev;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync memset(&Dev, 0, sizeof(SP_DEVINFO_DATA));
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync Dev.cbSize = sizeof(SP_DEVINFO_DATA);
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync if (!SetupDiEnumDeviceInfo(hDevInfo, dwDevId, &Dev))
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync winEr = GetLastError();
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if (winEr == ERROR_NO_MORE_ITEMS)
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync winEr = ERROR_SUCCESS;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync break;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync }
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: Enumerating device %ld ... \n", dwDevId));
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync dwDevId++;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if (pBuffer)
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync free(pBuffer);
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync pBuffer = NULL;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync DWORD cbBuffer = 0;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync DWORD cbRequired = 0;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if (!SetupDiGetDeviceRegistryPropertyW(hDevInfo, &Dev,
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync SPDRP_HARDWAREID, /* IN DWORD Property */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NULL, /* OUT PDWORD PropertyRegDataType OPTIONAL */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync pBuffer, /* OUT PBYTE PropertyBuffer */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync cbBuffer, /* IN DWORD PropertyBufferSize */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync &cbRequired /* OUT PDWORD RequiredSize OPTIONAL */))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync winEr = GetLastError();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (winEr != ERROR_INSUFFICIENT_BUFFER)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: SetupDiGetDeviceRegistryPropertyW (1) failed with %ld\n", winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pBuffer = (PBYTE)malloc(cbRequired);
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if (!pBuffer)
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: Out of memory allocating %ld bytes\n",
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync cbRequired));
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync winEr = ERROR_OUTOFMEMORY;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync break;
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync }
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync cbBuffer = cbRequired;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!SetupDiGetDeviceRegistryPropertyW(hDevInfo,&Dev,
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync SPDRP_HARDWAREID, /* IN DWORD Property */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NULL, /* OUT PDWORD PropertyRegDataType, OPTIONAL */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync pBuffer, /* OUT PBYTE PropertyBuffer */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync cbBuffer, /* IN DWORD PropertyBufferSize */
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync &cbRequired /* OUT PDWORD RequiredSize OPTIONAL */))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync winEr = GetLastError();
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: SetupDiGetDeviceRegistryPropertyW (2) failed with %ld\n",
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync PWSTR pCurId = (PWSTR)pBuffer;
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync size_t cCurId = wcslen(pCurId);
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: Device %ld: %S\n", dwDevId, pCurId));
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (cCurId >= cPnPId)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync pCurId += cCurId - cPnPId;
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync if (!wcsnicmp(pCurId, pwszPnPId, cPnPId))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync if (!callback(hDevInfo, &Dev, pContext))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: Found %ld devices total\n", dwDevId));
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pBuffer)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync free(pBuffer);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync hr = HRESULT_FROM_WIN32(winEr);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetupDiDestroyDeviceInfoList(hDevInfo);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD winEr = GetLastError();
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: SetupDiGetClassDevsExW failed with %ld\n", winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = HRESULT_FROM_WIN32(winEr);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
91000cbe6d6b2158c32ffe4b4bce4890f82fd1advboxsync NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices: Ended with hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRemoveAllNetDevicesOfId(IN LPCWSTR lpszPnPId)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return VBoxNetCfgWinEnumNetDevices(lpszPnPId, vboxNetCfgWinRemoveAllNetDevicesOfIdCallback, NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinPropChangeAllNetDevicesOfId(IN LPCWSTR lpszPnPId, VBOXNECTFGWINPROPCHANGE_TYPE enmPcType)
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync{
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync VBOXNECTFGWINPROPCHANGE Pc;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync Pc.enmPcType = enmPcType;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync Pc.hr = S_OK;
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync HRESULT hr = VBoxNetCfgWinEnumNetDevices(lpszPnPId, vboxNetCfgWinPropChangeAllNetDevicesOfIdCallback, &Pc);
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync if (!SUCCEEDED(hr))
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync {
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync NonStandardLogFlow(("VBoxNetCfgWinEnumNetDevices failed 0x%x\n", hr));
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync return hr;
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync }
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync if (!SUCCEEDED(Pc.hr))
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync {
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync NonStandardLogFlow(("vboxNetCfgWinPropChangeAllNetDevicesOfIdCallback failed 0x%x\n", Pc.hr));
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync return Pc.hr;
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync }
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync
72dd225c6e5a582baf12d8590c51d750b887fe5fvboxsync return S_OK;
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync}
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/*
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * logging
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic VOID DoLogging(LPCSTR szString, ...)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync LOG_ROUTINE pfnRoutine = (LOG_ROUTINE)(*((void * volatile *)&g_Logger));
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync if (pfnRoutine)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync char szBuffer[4096] = {0};
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync va_list va;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync va_start(va, szString);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync _vsnprintf(szBuffer, RT_ELEMENTS(szBuffer), szString, va);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync va_end(va);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync pfnRoutine(szBuffer);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(VOID) VBoxNetCfgWinSetLogging(IN LOG_ROUTINE pfnLog)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *((void * volatile *)&g_Logger) = pfnLog;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/*
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * IP configuration API
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* network settings config */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/**
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Strong referencing operators. Used as a second argument to ComPtr<>/ComObjPtr<>.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctemplate <class C>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncclass ComStrongRef
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncprotected:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync static void addref (C *p) { p->AddRef(); }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync static void release (C *p) { p->Release(); }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync};
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/**
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Base template for smart COM pointers. Not intended to be used directly.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctemplate <class C, template <class> class RefOps = ComStrongRef>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncclass ComPtrBase : protected RefOps <C>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncpublic:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* special template to disable AddRef()/Release() */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class I>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync class NoAddRefRelease : public I
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync private:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#if !defined (VBOX_WITH_XPCOM)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync STDMETHOD_(ULONG, AddRef)() = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync STDMETHOD_(ULONG, Release)() = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#else /* !defined (VBOX_WITH_XPCOM) */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NS_IMETHOD_(nsrefcnt) Release(void) = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif /* !defined (VBOX_WITH_XPCOM) */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync };
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncprotected:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtrBase () : p (NULL) {}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtrBase (const ComPtrBase &that) : p (that.p) { addref(); }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtrBase (C *that_p) : p (that_p) { addref(); }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ~ComPtrBase() { release(); }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtrBase &operator= (const ComPtrBase &that)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync safe_assign (that.p);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return *this;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtrBase &operator= (C *that_p)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync safe_assign (that_p);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return *this;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncpublic:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync void setNull()
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync p = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool isNull() const
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return (p == NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool operator! () const { return isNull(); }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool operator< (C* that_p) const { return p < that_p; }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool operator== (C* that_p) const { return p == that_p; }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class I>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool equalsTo (I *aThat) const
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return ComPtrEquals (p, aThat);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class OC>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool equalsTo (const ComPtrBase <OC> &oc) const
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return equalsTo ((OC *) oc);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Intended to pass instances as in parameters to interface methods */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync operator C* () const { return p; }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /**
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Dereferences the instance (redirects the -> operator to the managed
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * pointer).
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NoAddRefRelease <C> *operator-> () const
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync AssertMsg (p, ("Managed pointer must not be null\n"));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return (NoAddRefRelease <C> *) p;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class I>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT queryInterfaceTo (I **pp) const
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pp)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (p)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return p->QueryInterface (COM_IIDOF (I), (void **) pp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pp = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return E_INVALIDARG;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /** Intended to pass instances as out parameters to interface methods */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync C **asOutParam()
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync setNull();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return &p;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncprivate:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync void addref()
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (p)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RefOps <C>::addref (p);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync void release()
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (p)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RefOps <C>::release (p);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync void safe_assign (C *that_p)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* be aware of self-assignment */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (that_p)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RefOps <C>::addref (that_p);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync p = that_p;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync C *p;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync};
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/**
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Smart COM pointer wrapper that automatically manages refcounting of
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * interface pointers.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * @param I COM interface class
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctemplate <class I, template <class> class RefOps = ComStrongRef>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncclass ComPtr : public ComPtrBase <I, RefOps>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync typedef ComPtrBase <I, RefOps> Base;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncpublic:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr () : Base() {}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr (const ComPtr &that) : Base(that) {}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr &operator= (const ComPtr &that)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Base::operator= (that);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return *this;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class OI>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr (OI *that_p) : Base () { operator= (that_p); }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* specialization for I */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr (I *that_p) : Base (that_p) {}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class OC>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr (const ComPtr <OC, RefOps> &oc) : Base () { operator= ((OC *) oc); }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class OI>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr &operator= (OI *that_p)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (that_p)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync that_p->QueryInterface (COM_IIDOF (I), (void **) Base::asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Base::setNull();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return *this;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* specialization for I */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr &operator=(I *that_p)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Base::operator= (that_p);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return *this;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync template <class OC>
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr &operator= (const ComPtr <OC, RefOps> &oc)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return operator= ((OC *) oc);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync};
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinFindAdapterClassById(IWbemServices * pSvc, const GUID * pGuid, IWbemClassObject **pAdapterConfig)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync WCHAR wszQuery[256];
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync WCHAR wszGuid[50];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync int length = StringFromGUID2(*pGuid, wszGuid, RT_ELEMENTS(wszGuid));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (length)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync swprintf(wszQuery, L"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE SettingID = \"%s\"", wszGuid);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync IEnumWbemClassObject* pEnumerator = NULL;
99a5f7beff5f7bbf1f73923087d60070ddb717d4vboxsync hr = pSvc->ExecQuery(bstr_t("WQL"), bstr_t(wszQuery), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NULL, &pEnumerator);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pEnumerator)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync IWbemClassObject *pclsObj;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync ULONG uReturn = 0;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
99a5f7beff5f7bbf1f73923087d60070ddb717d4vboxsync NonStandardLogFlow(("netIfWinFindAdapterClassById: IEnumWbemClassObject::Next -> hr=0x%x pclsObj=%p uReturn=%u 42=%u\n",
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr, (void *)pclsObj, uReturn, 42));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync if (uReturn && pclsObj != NULL)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pAdapterConfig = pclsObj;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync pEnumerator->Release();
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("netIfWinFindAdapterClassById: S_OK and %p\n", *pAdapterConfig));
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync return S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = E_FAIL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pEnumerator->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync else
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("ExecQuery returned no enumerator\n"));
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = E_FAIL;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("ExecQuery failed (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD winEr = GetLastError();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = HRESULT_FROM_WIN32( winEr );
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync if (SUCCEEDED(hr))
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = E_FAIL;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("StringFromGUID2 failed winEr=%u, hr=0x%x\n", winEr, hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("netIfWinFindAdapterClassById: 0x%x and %p\n", hr, *pAdapterConfig));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinIsHostOnly(IWbemClassObject * pAdapterConfig, BOOL * pbIsHostOnly)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT vtServiceName;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BOOL bIsHostOnly = FALSE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantInit(&vtServiceName);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync HRESULT hr = pAdapterConfig->Get(L"ServiceName", 0 /*lFlags*/, &vtServiceName, NULL /*pvtType*/, NULL /*plFlavor*/);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync *pbIsHostOnly = bstr_t(vtServiceName.bstrVal) == bstr_t("VBoxNetAdp");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantClear(&vtServiceName);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinGetIpSettings(IWbemClassObject * pAdapterConfig, ULONG *pIpv4, ULONG *pMaskv4)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT vtIp;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantInit(&vtIp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pIpv4 = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pMaskv4 = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pAdapterConfig->Get(L"IPAddress", 0, &vtIp, 0, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (vtIp.vt == (VT_ARRAY | VT_BSTR))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT vtMask;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantInit(&vtMask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pAdapterConfig->Get(L"IPSubnet", 0, &vtMask, 0, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (vtMask.vt == (VT_ARRAY | VT_BSTR))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SAFEARRAY * pIpArray = vtIp.parray;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SAFEARRAY * pMaskArray = vtMask.parray;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pIpArray && pMaskArray)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR pCurIp;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR pCurMask;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (LONG i = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SafeArrayGetElement(pIpArray, &i, (PVOID)&pCurIp) == S_OK
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync && SafeArrayGetElement(pMaskArray, &i, (PVOID)&pCurMask) == S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync i++)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bstr_t ip(pCurIp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG Ipv4 = inet_addr((char*)(ip));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (Ipv4 != INADDR_NONE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pIpv4 = Ipv4;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bstr_t mask(pCurMask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pMaskv4 = inet_addr((char*)(mask));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pIpv4 = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pMaskv4 = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantClear(&vtMask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pIpv4 = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pMaskv4 = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantClear(&vtIp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinHasIpSettings(IWbemClassObject * pAdapterConfig, SAFEARRAY * pCheckIp, SAFEARRAY * pCheckMask, bool *pFound)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT vtIp;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantInit(&vtIp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pFound = false;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pAdapterConfig->Get(L"IPAddress", 0, &vtIp, 0, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT vtMask;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantInit(&vtMask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pAdapterConfig->Get(L"IPSubnet", 0, &vtMask, 0, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SAFEARRAY * pIpArray = vtIp.parray;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SAFEARRAY * pMaskArray = vtMask.parray;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pIpArray && pMaskArray)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR pIp, pMask;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (LONG k = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SafeArrayGetElement(pCheckIp, &k, (PVOID)&pIp) == S_OK
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync && SafeArrayGetElement(pCheckMask, &k, (PVOID)&pMask) == S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync k++)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR pCurIp;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR pCurMask;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (LONG i = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SafeArrayGetElement(pIpArray, &i, (PVOID)&pCurIp) == S_OK
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync && SafeArrayGetElement(pMaskArray, &i, (PVOID)&pCurMask) == S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync i++)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!wcsicmp(pCurIp, pIp))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!wcsicmp(pCurMask, pMask))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pFound = true;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantClear(&vtMask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantClear(&vtIp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinWaitIpSettings(IWbemServices *pSvc, const GUID * pGuid, SAFEARRAY * pCheckIp, SAFEARRAY * pCheckMask, ULONG sec2Wait, bool *pFound)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* on Vista we need to wait for the address to get applied */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* wait for the address to appear in the list */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG i;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pFound = false;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr <IWbemClassObject> pAdapterConfig;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (i = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync (hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam())) == S_OK
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync && (hr = netIfWinHasIpSettings(pAdapterConfig, pCheckIp, pCheckMask, pFound)) == S_OK
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync && !(*pFound)
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync && i < sec2Wait/6;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync i++)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Sleep(6000);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinCreateIWbemServices(IWbemServices ** ppSvc)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync IWbemLocator *pLoc = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync IWbemServices *pSvc = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pLoc->ConnectServer(bstr_t(L"ROOT\\CIMV2"), /* [in] const BSTR strNetworkResource */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NULL, /* [in] const BSTR strUser */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NULL, /* [in] const BSTR strPassword */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync 0, /* [in] const BSTR strLocale */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NULL, /* [in] LONG lSecurityFlags */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync 0, /* [in] const BSTR strAuthority */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync 0, /* [in] IWbemContext* pCtx */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &pSvc /* [out] IWbemServices** ppNamespace */);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = CoSetProxyBlanket(pSvc, /* IUnknown * pProxy */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RPC_C_AUTHN_WINNT, /* DWORD dwAuthnSvc */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RPC_C_AUTHZ_NONE, /* DWORD dwAuthzSvc */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NULL, /* WCHAR * pServerPrincName */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RPC_C_AUTHN_LEVEL_CALL, /* DWORD dwAuthnLevel */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RPC_C_IMP_LEVEL_IMPERSONATE, /* DWORD dwImpLevel */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NULL, /* RPC_AUTH_IDENTITY_HANDLE pAuthInfo */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync EOAC_NONE /* DWORD dwCapabilities */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync );
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *ppSvc = pSvc;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* do not need it any more */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pLoc->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("CoSetProxyBlanket failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pSvc->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("ConnectServer failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pLoc->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("CoCreateInstance failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinAdapterConfigPath(IWbemClassObject *pObj, BSTR * pStr)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT index;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pObj->Get(L"Index", 0, &index, 0, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync WCHAR strIndex[8];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync swprintf(strIndex, L"%u", index.uintVal);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pStr = (bstr_t(L"Win32_NetworkAdapterConfiguration.Index='") + strIndex + "'").copy();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Get failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfExecMethod(IWbemServices * pSvc, IWbemClassObject *pClass, BSTR ObjPath,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR MethodName, LPWSTR *pArgNames, LPVARIANT *pArgs, UINT cArgs,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync IWbemClassObject** ppOutParams
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync )
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr<IWbemClassObject> pInParamsDefinition;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr<IWbemClassObject> pClassInstance;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (cArgs)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pClass->GetMethod(MethodName, 0, pInParamsDefinition.asOutParam(), NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pInParamsDefinition->SpawnInstance(0, pClassInstance.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (UINT i = 0; i < cArgs; i++)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pClassInstance->Put(pArgNames[i], 0,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pArgs[i], 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync IWbemClassObject* pOutParams = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSvc->ExecMethod(ObjPath, MethodName, 0, NULL, pClassInstance, &pOutParams, NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *ppOutParams = pOutParams;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinCreateIpArray(SAFEARRAY **ppArray, in_addr* aIp, UINT cIp)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SAFEARRAY * pIpArray = SafeArrayCreateVector(VT_BSTR, 0, cIp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pIpArray)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (UINT i = 0; i < cIp; i++)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync char* addr = inet_ntoa(aIp[i]);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR val = bstr_t(addr).copy();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync long aIndex[1];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync aIndex[0] = i;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = SafeArrayPutElement(pIpArray, aIndex, val);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SysFreeString(val);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SafeArrayDestroy(pIpArray);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *ppArray = pIpArray;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = HRESULT_FROM_WIN32(GetLastError());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinCreateIpArrayV4V6(SAFEARRAY **ppArray, BSTR Ip)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SAFEARRAY *pIpArray = SafeArrayCreateVector(VT_BSTR, 0, 1);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pIpArray)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR val = bstr_t(Ip, false).copy();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync long aIndex[1];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync aIndex[0] = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = SafeArrayPutElement(pIpArray, aIndex, val);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (FAILED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SysFreeString(val);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SafeArrayDestroy(pIpArray);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *ppArray = pIpArray;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = HRESULT_FROM_WIN32(GetLastError());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinCreateIpArrayVariantV4(VARIANT * pIpAddresses, in_addr* aIp, UINT cIp)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantInit(pIpAddresses);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pIpAddresses->vt = VT_ARRAY | VT_BSTR;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SAFEARRAY *pIpArray;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinCreateIpArray(&pIpArray, aIp, cIp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pIpAddresses->parray = pIpArray;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinCreateIpArrayVariantV4V6(VARIANT * pIpAddresses, BSTR Ip)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantInit(pIpAddresses);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pIpAddresses->vt = VT_ARRAY | VT_BSTR;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SAFEARRAY *pIpArray;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinCreateIpArrayV4V6(&pIpArray, Ip);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pIpAddresses->parray = pIpArray;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinEnableStatic(IWbemServices * pSvc, const GUID * pGuid, BSTR ObjPath, VARIANT * pIp, VARIANT * pMask)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr<IWbemClassObject> pClass;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (ClassName)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync LPWSTR argNames[] = {L"IPAddress", L"SubnetMask"};
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync LPVARIANT args[] = {pIp, pMask};
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr<IWbemClassObject> pOutParams;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfExecMethod(pSvc, pClass, ObjPath, bstr_t(L"EnableStatic"), argNames, args, 2, pOutParams.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT varReturnValue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &varReturnValue, NULL, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Assert(SUCCEEDED(hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// Assert(varReturnValue.vt == VT_UINT);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync int winEr = varReturnValue.uintVal;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync switch (winEr)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync case 0:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// bool bFound;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// HRESULT tmpHr = netIfWinWaitIpSettings(pSvc, pGuid, pIp->parray, pMask->parray, 180, &bFound);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync default:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = HRESULT_FROM_WIN32( winEr );
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SysFreeString(ClassName);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = HRESULT_FROM_WIN32(GetLastError());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinEnableStaticV4(IWbemServices * pSvc, const GUID * pGuid, BSTR ObjPath, in_addr* aIp, in_addr * aMask, UINT cIp)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT ipAddresses;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = netIfWinCreateIpArrayVariantV4(&ipAddresses, aIp, cIp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT ipMasks;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinCreateIpArrayVariantV4(&ipMasks, aMask, cIp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinEnableStatic(pSvc, pGuid, ObjPath, &ipAddresses, &ipMasks);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantClear(&ipMasks);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantClear(&ipAddresses);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinEnableStaticV4V6(IWbemServices * pSvc, const GUID * pGuid, BSTR ObjPath, BSTR Ip, BSTR Mask)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT ipAddresses;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = netIfWinCreateIpArrayVariantV4V6(&ipAddresses, Ip);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT ipMasks;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinCreateIpArrayVariantV4V6(&ipMasks, Mask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinEnableStatic(pSvc, pGuid, ObjPath, &ipAddresses, &ipMasks);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantClear(&ipMasks);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantClear(&ipAddresses);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* win API allows to set gw metrics as well, we are not setting them */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinSetGateways(IWbemServices * pSvc, BSTR ObjPath, VARIANT * pGw)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr<IWbemClassObject> pClass;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (ClassName)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync LPWSTR argNames[] = {L"DefaultIPGateway"};
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync LPVARIANT args[] = {pGw};
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr<IWbemClassObject> pOutParams;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfExecMethod(pSvc, pClass, ObjPath, bstr_t(L"SetGateways"), argNames, args, 1, pOutParams.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT varReturnValue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0, &varReturnValue, NULL, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Assert(SUCCEEDED(hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// Assert(varReturnValue.vt == VT_UINT);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync int winEr = varReturnValue.uintVal;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync switch (winEr)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync case 0:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync default:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = HRESULT_FROM_WIN32( winEr );
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SysFreeString(ClassName);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = HRESULT_FROM_WIN32(GetLastError());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* win API allows to set gw metrics as well, we are not setting them */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinSetGatewaysV4(IWbemServices * pSvc, BSTR ObjPath, in_addr* aGw, UINT cGw)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT gwais;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = netIfWinCreateIpArrayVariantV4(&gwais, aGw, cGw);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync netIfWinSetGateways(pSvc, ObjPath, &gwais);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantClear(&gwais);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* win API allows to set gw metrics as well, we are not setting them */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinSetGatewaysV4V6(IWbemServices * pSvc, BSTR ObjPath, BSTR Gw)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT vGw;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = netIfWinCreateIpArrayVariantV4V6(&vGw, Gw);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync netIfWinSetGateways(pSvc, ObjPath, &vGw);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VariantClear(&vGw);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinEnableDHCP(IWbemServices * pSvc, BSTR ObjPath)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr<IWbemClassObject> pClass;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (ClassName)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr<IWbemClassObject> pOutParams;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfExecMethod(pSvc, pClass, ObjPath, bstr_t(L"EnableDHCP"), NULL, NULL, 0, pOutParams.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT varReturnValue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &varReturnValue, NULL, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Assert(SUCCEEDED(hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// Assert(varReturnValue.vt == VT_UINT);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync int winEr = varReturnValue.uintVal;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync switch (winEr)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync case 0:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync default:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = HRESULT_FROM_WIN32( winEr );
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SysFreeString(ClassName);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = HRESULT_FROM_WIN32(GetLastError());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfWinDhcpRediscover(IWbemServices * pSvc, BSTR ObjPath)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr<IWbemClassObject> pClass;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (ClassName)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr<IWbemClassObject> pOutParams;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfExecMethod(pSvc, pClass, ObjPath, bstr_t(L"ReleaseDHCPLease"), NULL, NULL, 0, pOutParams.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT varReturnValue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0, &varReturnValue, NULL, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Assert(SUCCEEDED(hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// Assert(varReturnValue.vt == VT_UINT);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync int winEr = varReturnValue.uintVal;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (winEr == 0)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfExecMethod(pSvc, pClass, ObjPath, bstr_t(L"RenewDHCPLease"), NULL, NULL, 0, pOutParams.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT varReturnValue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0, &varReturnValue, NULL, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Assert(SUCCEEDED(hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync // Assert(varReturnValue.vt == VT_UINT);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync int winEr = varReturnValue.uintVal;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (winEr == 0)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = HRESULT_FROM_WIN32( winEr );
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = HRESULT_FROM_WIN32( winEr );
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SysFreeString(ClassName);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = HRESULT_FROM_WIN32(GetLastError());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT vboxNetCfgWinIsDhcpEnabled(IWbemClassObject * pAdapterConfig, BOOL *pEnabled)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync VARIANT vtEnabled;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pAdapterConfig->Get(L"DHCPEnabled", 0, &vtEnabled, 0, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pEnabled = vtEnabled.boolVal;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGetAdapterSettings(IN const GUID * pGuid, OUT PADAPTER_SETTINGS pSettings)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr <IWbemServices> pSvc;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync ComPtr<IWbemClassObject> pAdapterConfig;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = vboxNetCfgWinIsDhcpEnabled(pAdapterConfig, &pSettings->bDhcp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinGetIpSettings(pAdapterConfig, &pSettings->ip, &pSettings->mask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinIsDhcpEnabled(const GUID * pGuid, BOOL *pEnabled)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync ComPtr <IWbemServices> pSvc;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync if (SUCCEEDED(hr))
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync ComPtr<IWbemClassObject> pAdapterConfig;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync VARIANT vtEnabled;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = pAdapterConfig->Get(L"DHCPEnabled", 0, &vtEnabled, 0, 0);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync *pEnabled = vtEnabled.boolVal;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinEnableStaticIpConfig(IN const GUID *pGuid, IN ULONG ip, IN ULONG mask)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("VBoxNetCfgWinEnableStaticIpConfig: ip=0x%x mask=0x%x", ip, mask));
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync ComPtr<IWbemServices> pSvc;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync HRESULT hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync if (SUCCEEDED(hr))
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync ComPtr<IWbemClassObject> pAdapterConfig;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync BOOL bIsHostOnly;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync if (bIsHostOnly)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync in_addr aIp[1];
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync in_addr aMask[1];
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync aIp[0].S_un.S_addr = ip;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync aMask[0].S_un.S_addr = mask;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync BSTR ObjPath;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync if (SUCCEEDED(hr))
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinEnableStaticV4(pSvc, pGuid, ObjPath, aIp, aMask, ip != 0 ? 1 : 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#if 0
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync in_addr aGw[1];
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync aGw[0].S_un.S_addr = gw;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinSetGatewaysV4(pSvc, ObjPath, aGw, 1);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync SysFreeString(ObjPath);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync else
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = E_FAIL;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync NonStandardLogFlow(("VBoxNetCfgWinEnableStaticIpConfig: returns 0x%x", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#if 0
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfEnableStaticIpConfigV6(const GUID *pGuid, IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask, IN_BSTR aIPV6DefaultGateway)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr <IWbemServices> pSvc;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync ComPtr<IWbemClassObject> pAdapterConfig;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR ObjPath;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinEnableStaticV4V6(pSvc, pAdapterConfig, ObjPath, aIPV6Address, aIPV6Mask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (aIPV6DefaultGateway)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinSetGatewaysV4V6(pSvc, ObjPath, aIPV6DefaultGateway);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// hr = netIfWinUpdateConfig(pIf);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SysFreeString(ObjPath);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return SUCCEEDED(hr) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT netIfEnableStaticIpConfigV6(const GUID *pGuid, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RTNETADDRIPV6 Mask;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync int rc = prefixLength2IPv6Address(aIPV6MaskPrefixLength, &Mask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (RT_SUCCESS(rc))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Bstr maskStr = composeIPv6Address(&Mask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync rc = netIfEnableStaticIpConfigV6(pGuid, aIPV6Address, maskStr, NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return rc;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#endif
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinEnableDynamicIpConfig(IN const GUID *pGuid)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ComPtr <IWbemServices> pSvc;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync ComPtr<IWbemClassObject> pAdapterConfig;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BOOL bIsHostOnly;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (bIsHostOnly)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BSTR ObjPath;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = netIfWinEnableDHCP(pSvc, ObjPath);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// hr = netIfWinUpdateConfig(pIf);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SysFreeString(ObjPath);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = E_FAIL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinDhcpRediscover(IN const GUID *pGuid)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync ComPtr <IWbemServices> pSvc;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinCreateIWbemServices(pSvc.asOutParam());
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync if (SUCCEEDED(hr))
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync ComPtr<IWbemClassObject> pAdapterConfig;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync BOOL bIsHostOnly;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync if (bIsHostOnly)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync BSTR ObjPath;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = netIfWinDhcpRediscover(pSvc, ObjPath);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync //hr = netIfWinUpdateConfig(pIf);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync SysFreeString(ObjPath);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync else
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync {
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync hr = E_FAIL;
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef bool (*PFNVBOXNETCFG_IPSETTINGS_CALLBACK) (ULONG ip, ULONG mask, PVOID pContext);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic void vboxNetCfgWinEnumIpConfig(PIP_ADAPTER_ADDRESSES pAddresses, PFNVBOXNETCFG_IPSETTINGS_CALLBACK pfnCallback, PVOID pContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PIP_ADAPTER_ADDRESSES pAdapter;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (pAdapter = pAddresses; pAdapter; pAdapter = pAdapter->Next)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PIP_ADAPTER_UNICAST_ADDRESS pAddr = pAdapter->FirstUnicastAddress;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PIP_ADAPTER_PREFIX pPrefix = pAdapter->FirstPrefix;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pAddr && pPrefix)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync do
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool fIPFound, fMaskFound;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync fIPFound = fMaskFound = false;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG ip, mask;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (; pAddr && !fIPFound; pAddr = pAddr->Next)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync switch (pAddr->Address.lpSockaddr->sa_family)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync case AF_INET:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync fIPFound = true;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync memcpy(&ip,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &((struct sockaddr_in *)pAddr->Address.lpSockaddr)->sin_addr.s_addr,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync sizeof(ip));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// case AF_INET6:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (; pPrefix && !fMaskFound; pPrefix = pPrefix->Next)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync switch (pPrefix->Address.lpSockaddr->sa_family)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync case AF_INET:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!pPrefix->PrefixLength || pPrefix->PrefixLength > 31) /* in case the ip helper API is queried while NetCfg write lock is held */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break; /* the address values can contain illegal values */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync fMaskFound = true;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync mask = (~(((ULONG)~0) >> pPrefix->PrefixLength));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync mask = htonl(mask);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// case AF_INET6:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync// break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!fIPFound || !fMaskFound)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!pfnCallback(ip, mask, pContext))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync } while (true);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsynctypedef struct _IPPROBE_CONTEXT
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG Prefix;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync bool bConflict;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}IPPROBE_CONTEXT, *PIPPROBE_CONTEXT;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define IPPROBE_INIT(_pContext, _addr) \
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ((_pContext)->bConflict = false, \
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync (_pContext)->Prefix = _addr)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define IPPROBE_INIT_STR(_pContext, _straddr) \
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync IPROBE_INIT(_pContext, inet_addr(_straddr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic bool vboxNetCfgWinIpProbeCallback (ULONG ip, ULONG mask, PVOID pContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PIPPROBE_CONTEXT pProbe = (PIPPROBE_CONTEXT)pContext;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if ((ip & mask) == (pProbe->Prefix & mask))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pProbe->bConflict = true;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return false;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return true;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGenHostOnlyNetworkNetworkIp(OUT PULONG pNetIp, OUT PULONG pNetMask)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD dwRc;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /*
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Most of the hosts probably have less than 10 adapters,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * so we'll mostly succeed from the first attempt.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG uBufLen = sizeof(IP_ADAPTER_ADDRESSES) * 10;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PIP_ADAPTER_ADDRESSES pAddresses = (PIP_ADAPTER_ADDRESSES)malloc(uBufLen);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!pAddresses)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync dwRc = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &uBufLen);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (dwRc == ERROR_BUFFER_OVERFLOW)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Impressive! More than 10 adapters! Get more memory and try again. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync free(pAddresses);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pAddresses = (PIP_ADAPTER_ADDRESSES)malloc(uBufLen);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!pAddresses)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync dwRc = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &uBufLen);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (dwRc == NO_ERROR)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync IPPROBE_CONTEXT Context;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync const ULONG ip192168 = inet_addr("192.168.0.0");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync srand(GetTickCount());
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pNetIp = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pNetMask = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (int i = 0; i < 255; i++)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG ipProbe = rand()*255/RAND_MAX;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ipProbe = ip192168 | (ipProbe << 16);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync IPPROBE_INIT(&Context, ipProbe);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync vboxNetCfgWinEnumIpConfig(pAddresses, vboxNetCfgWinIpProbeCallback, &Context);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!Context.bConflict)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pNetIp = ipProbe;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pNetMask = inet_addr("255.255.255.0");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (*pNetIp == 0)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync dwRc = ERROR_DHCP_ADDRESS_CONFLICT;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("GetAdaptersAddresses err (%d)\n", dwRc));
d97357e2036109245c83ba553d0290212e28ea40vboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (pAddresses)
d97357e2036109245c83ba553d0290212e28ea40vboxsync free(pAddresses);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (dwRc != NO_ERROR)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = HRESULT_FROM_WIN32(dwRc);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/*
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * convenience functions to perform netflt/adp manipulations
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETCFGWIN_NETFLT_ID L"sun_VBoxNetFlt"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOXNETCFGWIN_NETFLT_MP_ID L"sun_VBoxNetFltmp"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT vboxNetCfgWinNetFltUninstall(IN INetCfg *pNc, DWORD InfRmFlags)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
4ce3d4b5c12636b70579aed52e55fa8b4f49bff2vboxsync INetCfgComponent *pNcc = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = pNc->FindComponent(VBOXNETCFGWIN_NETFLT_ID, &pNcc);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hr == S_OK)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLog("NetFlt is installed currently, uninstalling ...\n");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = VBoxNetCfgWinUninstallComponent(pNc, pNcc);
678ec7791f4a65fc51306a98b7677a5d86bb9761vboxsync NonStandardLogFlow(("NetFlt component uninstallation ended with hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pNcc->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else if (hr == S_FALSE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLog("NetFlt is not installed currently\n");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("FindComponent failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
2fa05a4e777b070ba9bf01e3dd46434c99cd06a3vboxsync VBoxDrvCfgInfUninstallAllF(L"NetService", VBOXNETCFGWIN_NETFLT_ID, InfRmFlags);
2fa05a4e777b070ba9bf01e3dd46434c99cd06a3vboxsync VBoxDrvCfgInfUninstallAllF(L"Net", VBOXNETCFGWIN_NETFLT_MP_ID, InfRmFlags);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinNetFltUninstall(IN INetCfg *pNc)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return vboxNetCfgWinNetFltUninstall(pNc, 0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinNetFltInstall(IN INetCfg *pNc,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync IN LPCWSTR const *apInfFullPaths, IN UINT cInfFullPaths)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr = vboxNetCfgWinNetFltUninstall(pNc, SUOI_FORCEDELETE);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
d97357e2036109245c83ba553d0290212e28ea40vboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLog("NetFlt will be installed ...\n");
93186778b7c7dbfd0b5b135f56fe8434949ad2e8vboxsync hr = vboxNetCfgWinInstallInfAndComponent(pNc, VBOXNETCFGWIN_NETFLT_ID,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &GUID_DEVCLASS_NETSERVICE,
d97357e2036109245c83ba553d0290212e28ea40vboxsync apInfFullPaths,
d97357e2036109245c83ba553d0290212e28ea40vboxsync cInfFullPaths,
d97357e2036109245c83ba553d0290212e28ea40vboxsync NULL);
d97357e2036109245c83ba553d0290212e28ea40vboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync#define VBOXNETCFGWIN_NETADP_ID L"sun_VBoxNetAdp"
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsyncstatic HRESULT vboxNetCfgWinNetAdpUninstall(IN INetCfg *pNc, DWORD InfRmFlags)
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync{
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync INetCfgComponent *pNcc = NULL;
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync HRESULT hr = pNc->FindComponent(VBOXNETCFGWIN_NETADP_ID, &pNcc);
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync if (hr == S_OK)
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync {
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync NonStandardLog("NetAdp is installed currently, uninstalling ...\n");
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync hr = VBoxNetCfgWinUninstallComponent(pNc, pNcc);
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync NonStandardLogFlow(("NetAdp component uninstallation ended with hr (0x%x)\n", hr));
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync pNcc->Release();
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync }
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync else if (hr == S_FALSE)
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync {
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync NonStandardLog("NetAdp is not installed currently\n");
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync }
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync else
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync {
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync NonStandardLogFlow(("FindComponent failed, hr (0x%x)\n", hr));
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync }
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync VBoxDrvCfgInfUninstallAllF(L"Net", VBOXNETCFGWIN_NETADP_ID, InfRmFlags);
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync return hr;
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync}
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinNetAdpUninstall(IN INetCfg *pNc)
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync{
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync return vboxNetCfgWinNetAdpUninstall(pNc, 0);
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync}
46898cd9e04d40d7306ad1f6e957648072a70a22vboxsync
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync/*
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync * Use the same id as does the old implementation for NDIS 5
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync * #define VBOXNETCFGWIN_NETLWF_ID L"oracle_VBoxNetLwf"
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync */
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync#define VBOXNETCFGWIN_NETLWF_ID L"sun_VBoxNetFlt"
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsyncstatic HRESULT vboxNetCfgWinNetLwfUninstall(IN INetCfg *pNc, DWORD InfRmFlags)
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync{
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync INetCfgComponent * pNcc = NULL;
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync HRESULT hr = pNc->FindComponent(VBOXNETCFGWIN_NETLWF_ID, &pNcc);
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync if (hr == S_OK)
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync {
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync NonStandardLog("NetLwf is installed currently, uninstalling ...\n");
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync hr = VBoxNetCfgWinUninstallComponent(pNc, pNcc);
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync pNcc->Release();
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync }
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync else if (hr == S_FALSE)
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync {
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync NonStandardLog("NetLwf is not installed currently\n");
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync hr = S_OK;
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync }
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync else
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync {
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync NonStandardLogFlow(("FindComponent failed, hr (0x%x)\n", hr));
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync hr = S_OK;
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync }
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync VBoxDrvCfgInfUninstallAllF(L"NetService", VBOXNETCFGWIN_NETLWF_ID, InfRmFlags);
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync return hr;
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync}
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinNetLwfUninstall(IN INetCfg *pNc)
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync{
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync return vboxNetCfgWinNetLwfUninstall(pNc, 0);
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync}
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinNetLwfInstall(IN INetCfg *pNc,
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync IN LPCWSTR const pInfFullPath)
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync{
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync HRESULT hr = vboxNetCfgWinNetLwfUninstall(pNc, SUOI_FORCEDELETE);
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync if (SUCCEEDED(hr))
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync {
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync NonStandardLog("NetLwf will be installed ...\n");
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync hr = vboxNetCfgWinInstallInfAndComponent(pNc, VBOXNETCFGWIN_NETLWF_ID,
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync &GUID_DEVCLASS_NETSERVICE,
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync &pInfFullPath,
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync 1,
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync NULL);
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync }
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync return hr;
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync}
f3aabbf17ef1f076732e76f50abafaa4c28551d9vboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define VBOX_CONNECTION_NAME L"VirtualBox Host-Only Network"
d97357e2036109245c83ba553d0290212e28ea40vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGenHostonlyConnectionName(PCWSTR DevName, WCHAR *pBuf, PULONG pcbBuf)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync const WCHAR * pSuffix = wcsrchr( DevName, L'#' );
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG cbSize = sizeof(VBOX_CONNECTION_NAME);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG cbSufSize = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pSuffix)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync cbSize += (ULONG)wcslen(pSuffix) * 2;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync cbSize += 2; /* for space */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (*pcbBuf < cbSize)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync *pcbBuf = cbSize;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return E_FAIL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync wcscpy(pBuf, VBOX_CONNECTION_NAME);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pSuffix)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync wcscat(pBuf, L" ");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync wcscat(pBuf, pSuffix);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncstatic BOOL vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority(IN INetCfg *pNc, IN INetCfgComponent *pNcc, PVOID pContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
d97357e2036109245c83ba553d0290212e28ea40vboxsync INetCfgComponentBindings *pNetCfgBindings;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GUID *pGuid = (GUID*)pContext;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Get component's binding. */
d97357e2036109245c83ba553d0290212e28ea40vboxsync HRESULT hr = pNcc->QueryInterface(IID_INetCfgComponentBindings, (PVOID*)&pNetCfgBindings);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Get binding path enumerator reference. */
d97357e2036109245c83ba553d0290212e28ea40vboxsync IEnumNetCfgBindingPath *pEnumNetCfgBindPath;
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfgBindings->EnumBindingPaths(EBP_BELOW, &pEnumNetCfgBindPath);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync bool bFoundIface = false;
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pEnumNetCfgBindPath->Reset();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync do
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync INetCfgBindingPath *pNetCfgBindPath;
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pEnumNetCfgBindPath->Next(1, &pNetCfgBindPath, NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hr == S_OK)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync IEnumNetCfgBindingInterface *pEnumNetCfgBindIface;
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfgBindPath->EnumBindingInterfaces(&pEnumNetCfgBindIface);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (hr == S_OK)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync pEnumNetCfgBindIface->Reset();
d97357e2036109245c83ba553d0290212e28ea40vboxsync do
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync INetCfgBindingInterface *pNetCfgBindIfce;
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pEnumNetCfgBindIface->Next(1, &pNetCfgBindIfce, NULL);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (hr == S_OK)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync INetCfgComponent *pNetCfgCompo;
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfgBindIfce->GetLowerComponent(&pNetCfgCompo);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hr == S_OK)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync ULONG uComponentStatus;
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfgCompo->GetDeviceStatus(&uComponentStatus);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hr == S_OK)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync GUID guid;
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfgCompo->GetInstanceGuid(&guid);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if ( hr == S_OK
d97357e2036109245c83ba553d0290212e28ea40vboxsync && guid == *pGuid)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfgBindings->MoveAfter(pNetCfgBindPath, NULL);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hr))
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Unable to move interface, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsync bFoundIface = true;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync pNetCfgCompo->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("GetLowerComponent failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsync pNetCfgBindIfce->Release();
d97357e2036109245c83ba553d0290212e28ea40vboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync else
d97357e2036109245c83ba553d0290212e28ea40vboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (hr == S_FALSE) /* No more binding interfaces? */
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = S_OK;
d97357e2036109245c83ba553d0290212e28ea40vboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Next binding interface failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsync break;
d97357e2036109245c83ba553d0290212e28ea40vboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync } while (!bFoundIface);
d97357e2036109245c83ba553d0290212e28ea40vboxsync pEnumNetCfgBindIface->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("EnumBindingInterfaces failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsync pNetCfgBindPath->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
ba878f444ea591440183b70f65b2d309453b08c0vboxsync if (hr == S_FALSE) /* No more binding paths? */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Next bind path failed, hr (0x%x)\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync } while (!bFoundIface);
d97357e2036109245c83ba553d0290212e28ea40vboxsync pEnumNetCfgBindPath->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("EnumBindingPaths failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsync pNetCfgBindings->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("QueryInterface for IID_INetCfgComponentBindings failed, hr (0x%x)\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsync return TRUE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic UINT WINAPI vboxNetCfgWinPspFileCallback(
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PVOID Context,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT Notification,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT_PTR Param1,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync UINT_PTR Param2
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync )
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync switch (Notification)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync case SPFILENOTIFY_TARGETNEWER:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync case SPFILENOTIFY_TARGETEXISTS:
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return TRUE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return SetupDefaultQueueCallback(Context, Notification, Param1, Param2);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/* The original source of the VBoxNetAdp adapter creation/destruction code has the following copyright */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/*
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Copyright 2004 by the Massachusetts Institute of Technology
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync All rights reserved.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Permission to use, copy, modify, and distribute this software and its
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync documentation for any purpose and without fee is hereby granted,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync provided that the above copyright notice appear in all copies and that
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync both that copyright notice and this permission notice appear in
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync supporting documentation, and that the name of the Massachusetts
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync Institute of Technology (M.I.T.) not be used in advertising or publicity
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pertaining to distribution of the software without specific, written
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync prior permission.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SOFTWARE.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync*/
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/**
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Use the IShellFolder API to rename the connection.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncstatic HRESULT rename_shellfolder (PCWSTR wGuid, PCWSTR wNewName)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* This is the GUID for the network connections folder. It is constant.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * {7007ACC7-3202-11D1-AAD2-00805FC1270E} */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync const GUID CLSID_NetworkConnections = {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync 0x7007ACC7, 0x3202, 0x11D1, {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync 0xAA, 0xD2, 0x00, 0x80, 0x5F, 0xC1, 0x27, 0x0E
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync };
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync LPITEMIDLIST pidl = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync IShellFolder *pShellFolder = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Build the display name in the form "::{GUID}". */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync if (wcslen(wGuid) >= MAX_PATH)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return E_INVALIDARG;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync WCHAR szAdapterGuid[MAX_PATH + 2] = {0};
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync swprintf(szAdapterGuid, L"::%ls", wGuid);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Create an instance of the network connections folder. */
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync hr = CoCreateInstance(CLSID_NetworkConnections, NULL,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync CLSCTX_INPROC_SERVER, IID_IShellFolder,
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync reinterpret_cast<LPVOID *>(&pShellFolder));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Parse the display name. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED (hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pShellFolder->ParseDisplayName (NULL, NULL, szAdapterGuid, NULL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &pidl, NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED (hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hr = pShellFolder->SetNameOf (NULL, pidl, wNewName, SHGDN_NORMAL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &pidl);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync CoTaskMemFree (pidl);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pShellFolder)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pShellFolder->Release();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hr;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync/**
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * Loads a system DLL.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync *
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * @returns Module handle or NULL
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * @param pszName The DLL name.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync */
71955773a7f477f9a159a491f765ba97e1f00e1avboxsyncstatic HMODULE loadSystemDll(const char *pszName)
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync{
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync char szPath[MAX_PATH];
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync UINT cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync size_t cbName = strlen(pszName) + 1;
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync if (cchPath + 1 + cbName > sizeof(szPath))
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync return NULL;
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync szPath[cchPath] = '\\';
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync memcpy(&szPath[cchPath + 1], pszName, cbName);
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync return LoadLibraryA(szPath);
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync}
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRenameConnection (LPWSTR pGuid, PCWSTR NewName)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync typedef HRESULT (WINAPI *lpHrRenameConnection) (const GUID *, PCWSTR);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync lpHrRenameConnection RenameConnectionFunc = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT status;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* First try the IShellFolder interface, which was unimplemented
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * for the network connections folder before XP. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync status = rename_shellfolder (pGuid, NewName);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (status == E_NOTIMPL)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync/** @todo that code doesn't seem to work! */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* The IShellFolder interface is not implemented on this platform.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Try the (undocumented) HrRenameConnection API in the netshell
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * library. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync CLSID clsid;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HINSTANCE hNetShell;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync status = CLSIDFromString ((LPOLESTR) pGuid, &clsid);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (FAILED(status))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return E_FAIL;
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync hNetShell = loadSystemDll("netshell.dll");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hNetShell == NULL)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return E_FAIL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RenameConnectionFunc =
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync (lpHrRenameConnection) GetProcAddress (hNetShell,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync "HrRenameConnection");
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (RenameConnectionFunc == NULL)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync FreeLibrary (hNetShell);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return E_FAIL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync status = RenameConnectionFunc (&clsid, NewName);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync FreeLibrary (hNetShell);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (FAILED (status))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return status;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define DRIVERHWID _T("sun_VBoxNetAdp")
6db5dfa0985f898dd0497d98716b6d0335a9dde4vboxsync#define DRIVERHWID_NDIS6 _T("sun_VBoxNetAdp6")
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#define SetErrBreak(strAndArgs) \
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (1) { \
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hrc = E_FAIL; \
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLog strAndArgs; \
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break; \
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync } else do {} while (0)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRemoveHostOnlyNetworkInterface(IN const GUID *pGUID, OUT BSTR *pErrMsg)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hrc = S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync do
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync TCHAR lszPnPInstanceId [512] = {0};
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* We have to find the device instance ID through a registry search */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HKEY hkeyNetwork = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HKEY hkeyConnection = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync do
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync WCHAR strRegLocation [256];
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync WCHAR wszGuid[50];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync int length = StringFromGUID2(*pGUID, wszGuid, RT_ELEMENTS(wszGuid));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!length)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak(("Failed to create a Guid string"));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync swprintf (strRegLocation,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync L"SYSTEM\\CurrentControlSet\\Control\\Network\\"
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync L"{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s",
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync wszGuid);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync LONG status;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync status = RegOpenKeyExW (HKEY_LOCAL_MACHINE, strRegLocation, 0,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync KEY_READ, &hkeyNetwork);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if ((status != ERROR_SUCCESS) || !hkeyNetwork)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("Host interface network is not found in registry (%S) [1]",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync strRegLocation));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync status = RegOpenKeyExW (hkeyNetwork, L"Connection", 0,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync KEY_READ, &hkeyConnection);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if ((status != ERROR_SUCCESS) || !hkeyConnection)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("Host interface network is not found in registry (%S) [2]",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync strRegLocation));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD len = sizeof (lszPnPInstanceId);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD dwKeyType;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync status = RegQueryValueExW (hkeyConnection, L"PnPInstanceID", NULL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &dwKeyType, (LPBYTE) lszPnPInstanceId, &len);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if ((status != ERROR_SUCCESS) || (dwKeyType != REG_SZ))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("Host interface network is not found in registry (%S) [3]",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync strRegLocation));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync while (0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hkeyConnection)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RegCloseKey (hkeyConnection);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hkeyNetwork)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RegCloseKey (hkeyNetwork);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (FAILED (hrc))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /*
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Now we are going to enumerate all network devices and
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * wait until we encounter the right device instance ID
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HDEVINFO hDeviceInfo = INVALID_HANDLE_VALUE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync do
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BOOL ok;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD ret = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GUID netGuid;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SP_DEVINFO_DATA DeviceInfoData;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD index = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BOOL found = FALSE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD size = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* initialize the structure size */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInfoData.cbSize = sizeof (SP_DEVINFO_DATA);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* copy the net class GUID */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync memcpy (&netGuid, &GUID_DEVCLASS_NET, sizeof (GUID_DEVCLASS_NET));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* return a device info set contains all installed devices of the Net class */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hDeviceInfo = SetupDiGetClassDevs (&netGuid, NULL, NULL, DIGCF_PRESENT);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hDeviceInfo == INVALID_HANDLE_VALUE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiGetClassDevs failed (0x%08X)", GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* enumerate the driver info list */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync while (TRUE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync TCHAR *deviceHwid;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ok = SetupDiEnumDeviceInfo (hDeviceInfo, index, &DeviceInfoData);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!ok)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (GetLastError() == ERROR_NO_MORE_ITEMS)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync index++;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync continue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* try to get the hardware ID registry property */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ok = SetupDiGetDeviceRegistryProperty (hDeviceInfo,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SPDRP_HARDWAREID,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NULL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NULL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync 0,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &size);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!ok)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync index++;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync continue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync deviceHwid = (TCHAR *) malloc (size);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ok = SetupDiGetDeviceRegistryProperty (hDeviceInfo,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SPDRP_HARDWAREID,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NULL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync (PBYTE)deviceHwid,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync size,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!ok)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync free (deviceHwid);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync deviceHwid = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync index++;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync continue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* something is wrong. This shouldn't have worked with a NULL buffer */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync index++;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync continue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync for (TCHAR *t = deviceHwid;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync t && *t && t < &deviceHwid[size / sizeof(TCHAR)];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync t += _tcslen (t) + 1)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
6db5dfa0985f898dd0497d98716b6d0335a9dde4vboxsync if (!_tcsicmp (DRIVERHWID, t) || !_tcsicmp (DRIVERHWID_NDIS6, t))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* get the device instance ID */
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync TCHAR devId[MAX_DEVICE_ID_LEN];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (CM_Get_Device_ID(DeviceInfoData.DevInst,
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync devId, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* compare to what we determined before */
468190b22aeddd68559df8a742aef64ee8974d0bvboxsync if (wcscmp(devId, lszPnPInstanceId) == 0)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync found = TRUE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (deviceHwid)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync free (deviceHwid);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync deviceHwid = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (found)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync index++;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (found == FALSE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("Host Interface Network driver not found (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ok = SetupDiSetSelectedDevice (hDeviceInfo, &DeviceInfoData);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!ok)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiSetSelectedDevice failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ok = SetupDiCallClassInstaller (DIF_REMOVE, hDeviceInfo, &DeviceInfoData);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!ok)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync while (0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* clean up the device info set */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hDeviceInfo != INVALID_HANDLE_VALUE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetupDiDestroyDeviceInfoList (hDeviceInfo);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (FAILED (hrc))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync while (0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hrc;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
6db5dfa0985f898dd0497d98716b6d0335a9dde4vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinUpdateHostOnlyNetworkInterface(LPCWSTR pcsxwInf, BOOL *pbRebootRequired, LPCWSTR pcsxwId)
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync{
6db5dfa0985f898dd0497d98716b6d0335a9dde4vboxsync return VBoxDrvCfgDrvUpdate(pcsxwId, pcsxwInf, pbRebootRequired);
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync}
7c63dd76442a4896af6ce9c65d87461d3e7fe82bvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsyncVBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile,
d97357e2036109245c83ba553d0290212e28ea40vboxsync OUT GUID *pGuid, OUT BSTR *lppszName, OUT BSTR *pErrMsg)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync{
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HRESULT hrc = S_OK;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HDEVINFO hDeviceInfo = INVALID_HANDLE_VALUE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SP_DEVINFO_DATA DeviceInfoData;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PVOID pQueueCallbackContext = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD ret = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BOOL found = FALSE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BOOL registered = FALSE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BOOL destroyList = FALSE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync WCHAR pWCfgGuidString [50];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync WCHAR DevName[256];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync do
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GUID netGuid;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SP_DRVINFO_DATA DriverInfoData;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SP_DEVINSTALL_PARAMS DeviceInstallParams;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync TCHAR className [MAX_PATH];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD index = 0;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync PSP_DRVINFO_DETAIL_DATA pDriverInfoDetail;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* for our purposes, 2k buffer is more
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * than enough to obtain the hardware ID
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * of the VBoxNetAdp driver. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD detailBuf [2048];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync HKEY hkey = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD cbSize;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD dwValueType;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* initialize the structure size */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInfoData.cbSize = sizeof (SP_DEVINFO_DATA);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DriverInfoData.cbSize = sizeof (SP_DRVINFO_DATA);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* copy the net class GUID */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync memcpy(&netGuid, &GUID_DEVCLASS_NET, sizeof(GUID_DEVCLASS_NET));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* create an empty device info set associated with the net class GUID */
d97357e2036109245c83ba553d0290212e28ea40vboxsync hDeviceInfo = SetupDiCreateDeviceInfoList(&netGuid, NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hDeviceInfo == INVALID_HANDLE_VALUE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCreateDeviceInfoList failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* get the class name from GUID */
d97357e2036109245c83ba553d0290212e28ea40vboxsync BOOL fResult = SetupDiClassNameFromGuid (&netGuid, className, MAX_PATH, NULL);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiClassNameFromGuid failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* create a device info element and add the new device instance
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * key to registry */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCreateDeviceInfo (hDeviceInfo, className, &netGuid, NULL, NULL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DICD_GENERATE_ID, &DeviceInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCreateDeviceInfo failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* select the newly created device info to be the currently
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync selected member */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiSetSelectedDevice (hDeviceInfo, &DeviceInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiSetSelectedDevice failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pInfPath)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* get the device install parameters and disable filecopy */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &DeviceInstallParams);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync memset(DeviceInstallParams.DriverPath, 0, sizeof(DeviceInstallParams.DriverPath));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync size_t pathLenght = wcslen(pInfPath) + 1/* null terminator */;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pathLenght < sizeof(DeviceInstallParams.DriverPath)/sizeof(DeviceInstallParams.DriverPath[0]))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync memcpy(DeviceInstallParams.DriverPath, pInfPath, pathLenght*sizeof(DeviceInstallParams.DriverPath[0]));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (bIsInfPathFile)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInstallParams.Flags |= DI_ENUMSINGLEINF;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiSetDeviceInstallParams(hDeviceInfo, &DeviceInfoData,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &DeviceInstallParams);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD winEr = GetLastError();
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiSetDeviceInstallParams failed, winEr (%d)\n", winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiSetDeviceInstallParams faileed: INF path is too long\n"));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD winEr = GetLastError();
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiGetDeviceInstallParams failed, winEr (%d)\n", winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* build a list of class drivers */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiBuildDriverInfoList (hDeviceInfo, &DeviceInfoData,
d97357e2036109245c83ba553d0290212e28ea40vboxsync SPDIT_CLASSDRIVER);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiBuildDriverInfoList failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync destroyList = TRUE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* enumerate the driver info list */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync while (TRUE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync BOOL ret;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ret = SetupDiEnumDriverInfo (hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SPDIT_CLASSDRIVER, index, &DriverInfoData);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* if the function failed and GetLastError() returned
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * ERROR_NO_MORE_ITEMS, then we have reached the end of the
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * list. Otherwise there was something wrong with this
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * particular driver. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!ret)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (GetLastError() == ERROR_NO_MORE_ITEMS)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync index++;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync continue;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pDriverInfoDetail = (PSP_DRVINFO_DETAIL_DATA) detailBuf;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pDriverInfoDetail->cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* if we successfully find the hardware ID and it turns out to
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * be the one for the loopback driver, then we are done. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SetupDiGetDriverInfoDetail (hDeviceInfo,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &DriverInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pDriverInfoDetail,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync sizeof (detailBuf),
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NULL))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync TCHAR * t;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* pDriverInfoDetail->HardwareID is a MULTISZ string. Go through the
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * whole list and see if there is a match somewhere. */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync t = pDriverInfoDetail->HardwareID;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync while (t && *t && t < (TCHAR *) &detailBuf [RT_ELEMENTS(detailBuf)])
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
6db5dfa0985f898dd0497d98716b6d0335a9dde4vboxsync if (!_tcsicmp(t, DRIVERHWID) || !_tcsicmp(t, DRIVERHWID_NDIS6))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync t += _tcslen(t) + 1;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (t && *t && t < (TCHAR *) &detailBuf [RT_ELEMENTS(detailBuf)])
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync found = TRUE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync break;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync index ++;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!found)
d97357e2036109245c83ba553d0290212e28ea40vboxsync SetErrBreak(("Could not find Host Interface Networking driver! Please reinstall"));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* set the loopback driver to be the currently selected */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiSetSelectedDriver (hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &DriverInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
d97357e2036109245c83ba553d0290212e28ea40vboxsync SetErrBreak(("SetupDiSetSelectedDriver failed (0x%08X)",
d97357e2036109245c83ba553d0290212e28ea40vboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* register the phantom device to prepare for install */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller (DIF_REGISTERDEVICE, hDeviceInfo,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &DeviceInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD err = GetLastError();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync err));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* registered, but remove if errors occur in the following code */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync registered = TRUE;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* ask the installer if we can install the device */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller (DIF_ALLOW_INSTALL, hDeviceInfo,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &DeviceInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (GetLastError() != ERROR_DI_DO_DEFAULT)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller (DIF_ALLOW_INSTALL) failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* that's fine */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* get the device install parameters and disable filecopy */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &DeviceInstallParams);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync pQueueCallbackContext = SetupInitDefaultQueueCallback(NULL);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pQueueCallbackContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInstallParams.InstallMsgHandlerContext = pQueueCallbackContext;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInstallParams.InstallMsgHandler = (PSP_FILE_CALLBACK)vboxNetCfgWinPspFileCallback;
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiSetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &DeviceInstallParams);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD winEr = GetLastError();
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiSetDeviceInstallParams failed, winEr (%d)\n", winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync Assert(fResult);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD winEr = GetLastError();
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupInitDefaultQueueCallback failed, winEr (%d)\n", winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD winEr = GetLastError();
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SetupDiGetDeviceInstallParams failed, winEr (%d)\n", winEr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* install the files first */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller (DIF_INSTALLDEVICEFILES, hDeviceInfo,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &DeviceInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller (DIF_INSTALLDEVICEFILES) failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* get the device install parameters and disable filecopy */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &DeviceInstallParams);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DeviceInstallParams.Flags |= DI_NOFILECOPY;
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiSetDeviceInstallParams(hDeviceInfo, &DeviceInfoData,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &DeviceInstallParams);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiSetDeviceInstallParams failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /*
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * Register any device-specific co-installers for this device,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller(DIF_REGISTER_COINSTALLERS,
d97357e2036109245c83ba553d0290212e28ea40vboxsync hDeviceInfo,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &DeviceInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller (DIF_REGISTER_COINSTALLERS) failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /*
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * install any installer-specified interfaces.
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * and then do the real install
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller(DIF_INSTALLINTERFACES,
d97357e2036109245c83ba553d0290212e28ea40vboxsync hDeviceInfo,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &DeviceInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller (DIF_INSTALLINTERFACES) failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync fResult = SetupDiCallClassInstaller(DIF_INSTALLDEVICE,
d97357e2036109245c83ba553d0290212e28ea40vboxsync hDeviceInfo,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &DeviceInfoData);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (!fResult)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiCallClassInstaller (DIF_INSTALLDEVICE) failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* Figure out NetCfgInstanceId */
d97357e2036109245c83ba553d0290212e28ea40vboxsync hkey = SetupDiOpenDevRegKey(hDeviceInfo,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &DeviceInfoData,
d97357e2036109245c83ba553d0290212e28ea40vboxsync DICS_FLAG_GLOBAL,
d97357e2036109245c83ba553d0290212e28ea40vboxsync 0,
d97357e2036109245c83ba553d0290212e28ea40vboxsync DIREG_DRV,
d97357e2036109245c83ba553d0290212e28ea40vboxsync KEY_READ);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hkey == INVALID_HANDLE_VALUE)
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync SetErrBreak(("SetupDiOpenDevRegKey failed (0x%08X)", GetLastError()));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
f6ae8a8ac76f00fb06168fcf2e28e9f4ae8ed438vboxsync cbSize = sizeof(pWCfgGuidString);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync DWORD ret;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ret = RegQueryValueExW (hkey, L"NetCfgInstanceId", NULL,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync &dwValueType, (LPBYTE) pWCfgGuidString, &cbSize);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync RegCloseKey (hkey);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!SetupDiGetDeviceRegistryPropertyW(hDeviceInfo, &DeviceInfoData,
d97357e2036109245c83ba553d0290212e28ea40vboxsync SPDRP_FRIENDLYNAME , /* IN DWORD Property,*/
d97357e2036109245c83ba553d0290212e28ea40vboxsync NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/
d97357e2036109245c83ba553d0290212e28ea40vboxsync (PBYTE)DevName, /*OUT PBYTE PropertyBuffer,*/
d97357e2036109245c83ba553d0290212e28ea40vboxsync sizeof(DevName), /* IN DWORD PropertyBufferSize,*/
d97357e2036109245c83ba553d0290212e28ea40vboxsync NULL /*OUT PDWORD RequiredSize OPTIONAL*/))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync int err = GetLastError();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (err != ERROR_INVALID_DATA)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiGetDeviceRegistryProperty failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync err));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!SetupDiGetDeviceRegistryPropertyW(hDeviceInfo, &DeviceInfoData,
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SPDRP_DEVICEDESC, /* IN DWORD Property,*/
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync (PBYTE)DevName, /*OUT PBYTE PropertyBuffer,*/
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync sizeof(DevName), /* IN DWORD PropertyBufferSize,*/
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync NULL /*OUT PDWORD RequiredSize OPTIONAL*/
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync err = GetLastError();
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetErrBreak (("SetupDiGetDeviceRegistryProperty failed (0x%08X)",
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync err));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync while (0);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /*
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync * cleanup
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pQueueCallbackContext)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetupTermDefaultQueueCallback(pQueueCallbackContext);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hDeviceInfo != INVALID_HANDLE_VALUE)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* an error has occurred, but the device is registered, we must remove it */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (ret != 0 && registered)
d97357e2036109245c83ba553d0290212e28ea40vboxsync SetupDiCallClassInstaller(DIF_REMOVE, hDeviceInfo, &DeviceInfoData);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync found = SetupDiDeleteDeviceInfo(hDeviceInfo, &DeviceInfoData);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* destroy the driver info list */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (destroyList)
d97357e2036109245c83ba553d0290212e28ea40vboxsync SetupDiDestroyDriverInfoList(hDeviceInfo, &DeviceInfoData,
d97357e2036109245c83ba553d0290212e28ea40vboxsync SPDIT_CLASSDRIVER);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* clean up the device info set */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync SetupDiDestroyDeviceInfoList (hDeviceInfo);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync /* return the network connection GUID on success */
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (SUCCEEDED(hrc))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync WCHAR ConnectoinName[128];
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync ULONG cbName = sizeof(ConnectoinName);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName(DevName, ConnectoinName, &cbName);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = VBoxNetCfgWinRenameConnection(pWCfgGuidString, ConnectoinName);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (lppszName)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
10330aa61b0abd8a82e3dd9fb2ad064ec64ac900vboxsync *lppszName = SysAllocString((const OLECHAR *) DevName);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (!*lppszName)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("SysAllocString failed\n"));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hrc = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (pGuid)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync hrc = CLSIDFromString(pWCfgGuidString, (LPCLSID)pGuid);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (FAILED(hrc))
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("CLSIDFromString failed, hrc (0x%x)\n", hrc));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync INetCfg *pNetCfg = NULL;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync LPWSTR lpszApp = NULL;
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = VBoxNetCfgWinQueryINetCfg(&pNetCfg, TRUE, L"VirtualBox Host-Only Creation",
d97357e2036109245c83ba553d0290212e28ea40vboxsync 30 * 1000, /* on Vista we often get 6to4svc.dll holding the lock, wait for 30 sec. */
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* TODO: special handling for 6to4svc.dll ???, i.e. several retrieves */
d97357e2036109245c83ba553d0290212e28ea40vboxsync &lpszApp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync if (hr == S_OK)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &GUID_DEVCLASS_NETSERVICE,
d97357e2036109245c83ba553d0290212e28ea40vboxsync vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,
d97357e2036109245c83ba553d0290212e28ea40vboxsync pGuid);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &GUID_DEVCLASS_NETTRANS,
d97357e2036109245c83ba553d0290212e28ea40vboxsync vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,
d97357e2036109245c83ba553d0290212e28ea40vboxsync pGuid);
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg,
d97357e2036109245c83ba553d0290212e28ea40vboxsync &GUID_DEVCLASS_NETCLIENT,
d97357e2036109245c83ba553d0290212e28ea40vboxsync vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority,
d97357e2036109245c83ba553d0290212e28ea40vboxsync pGuid);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
d97357e2036109245c83ba553d0290212e28ea40vboxsync if (SUCCEEDED(hr))
d97357e2036109245c83ba553d0290212e28ea40vboxsync {
d97357e2036109245c83ba553d0290212e28ea40vboxsync hr = pNetCfg->Apply();
d97357e2036109245c83ba553d0290212e28ea40vboxsync }
d97357e2036109245c83ba553d0290212e28ea40vboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Enumeration failed, hr 0x%x\n", hr));
d97357e2036109245c83ba553d0290212e28ea40vboxsync VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszApp)
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync {
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("Application %ws is holding the lock, failed\n", lpszApp));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync CoTaskMemFree(lpszApp);
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync else
3581dfd579fa647c95528b7f7d24740111a36903vboxsync NonStandardLogFlow(("VBoxNetCfgWinQueryINetCfg failed, hr 0x%x\n", hr));
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync }
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync return hrc;
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync}
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync
3331475701a5b12f98b3cfea07d5dca60072530fvboxsync#undef SetErrBreak
d97357e2036109245c83ba553d0290212e28ea40vboxsync