Skip to content

Commit

Permalink
[NETSHELL] Improvements to the network setup (1/x)
Browse files Browse the repository at this point in the history
Step 1: Find the TcpIp transport and enumerate the installed network adapters using INetCfg.

Next Step: Find out how the binding process works and bind the TcpIp transport to all enumerated network adapters. This will replace the blind binding process we are using right now.
  • Loading branch information
EricKohl committed Jun 16, 2019
1 parent 24b22db commit 78f13ae
Showing 1 changed file with 143 additions and 0 deletions.
143 changes: 143 additions & 0 deletions dll/shellext/netshell/setup.cpp
Expand Up @@ -35,6 +35,146 @@ SetBoldText(
SendDlgItemMessageW(hwndDlg, control, WM_SETFONT, (WPARAM)pSetupData->hBoldFont, MAKELPARAM(TRUE, 0));
}


static
HRESULT
InstallTypicalNetworkSettings(VOID)
{
INetCfg *pNetCfg = NULL;
INetCfgLock *pNetCfgLock = NULL;
INetCfgComponent *pTcpipComponent = NULL;
INetCfgComponent *pNicComponent = NULL;
IEnumNetCfgComponent *pEnumNicComponents = NULL;
WCHAR *pszNicName;
BOOL fWriteLocked = FALSE, fInitialized = FALSE;
HRESULT hr;

TRACE("InstallTypicalNetworkSettings()\n");

hr = CoInitialize(NULL);
if (hr != S_OK)
{
ERR("CoInitialize failed\n");
goto exit;
}

hr = CoCreateInstance(CLSID_CNetCfg,
NULL,
CLSCTX_INPROC_SERVER,
IID_INetCfg,
(PVOID*)&pNetCfg);
if (hr != S_OK)
{
ERR("CoCreateInstance failed\n");
goto exit;
}

/* Acquire the write-lock */
hr = pNetCfg->QueryInterface(IID_INetCfgLock,
(PVOID*)&pNetCfgLock);
if (hr != S_OK)
{
ERR("QueryInterface failed\n");
goto exit;
}

hr = pNetCfgLock->AcquireWriteLock(5000,
L"SysSetup",
NULL);
if (hr != S_OK)
{
ERR("AcquireWriteLock failed\n");
goto exit;
}

fWriteLocked = TRUE;

/* Initialize the network configuration */
hr = pNetCfg->Initialize(NULL);
if (hr != S_OK)
{
ERR("Initialize failed\n");
goto exit;
}

fInitialized = TRUE;

/* Find the TCP/IP driver */
hr = pNetCfg->FindComponent(L"ms_tcpip",
&pTcpipComponent);
if (hr == S_OK)
{
FIXME("Found the TCP/IP driver!\n");
}
else
{
ERR("Initialize failed\n");
goto exit;
}

hr = pNetCfg->EnumComponents(&GUID_DEVCLASS_NET,
&pEnumNicComponents);
if (hr != S_OK)
{
ERR("EnumComponents failed\n");
goto exit;
}

for (;;)
{
hr = pEnumNicComponents->Next(1,
&pNicComponent,
NULL);
if (hr != S_OK)
{
TRACE("EnumNicComponents done!\n");
break;
}

hr = pNicComponent->GetDisplayName(&pszNicName);
if (hr == S_OK)
{
FIXME("NIC name: %S\n", pszNicName);
CoTaskMemFree(pszNicName);
}

// FIXME Bind Tcpip to the NIC

pNicComponent->Release();
pNicComponent = NULL;
}

TRACE("Done!\n");
exit:
if (pNicComponent != NULL)
pNicComponent->Release();

if (pEnumNicComponents != NULL)
pEnumNicComponents->Release();

if (pTcpipComponent != NULL)
pTcpipComponent->Release();

if (fInitialized)
pNetCfg->Uninitialize();

if (fWriteLocked)
pNetCfgLock->ReleaseWriteLock();

if (pNetCfgLock != NULL)
pNetCfgLock->Release();

if (pNetCfg != NULL)
pNetCfg->Release();

CoUninitialize();

TRACE("InstallTypicalNetworkSettings() done!\n");

return hr;
}


static
INT_PTR
CALLBACK
Expand Down Expand Up @@ -102,6 +242,9 @@ NetworkSettingsPageDlgProc(
if (IsDlgButtonChecked(hwndDlg, IDC_NETWORK_TYPICAL) == BST_CHECKED)
{
pNetworkSetupData->bTypicalNetworkSetup = TRUE;

InstallTypicalNetworkSettings();

SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKDOMAINPAGE);
return TRUE;
}
Expand Down

0 comments on commit 78f13ae

Please sign in to comment.