- Store NTEContext for IPAddress

- Call DeleteIPAddress and AddIPAddress for adapters when applying changes

svn path=/trunk/; revision=37041
This commit is contained in:
Johannes Anderwald 2008-10-28 15:31:36 +00:00
parent a83186227a
commit 0e6210c139

View file

@ -34,6 +34,7 @@ typedef struct tagIP_ADDR
DWORD Subnetmask;
USHORT Metric;
}u;
ULONG NTEContext;
struct tagIP_ADDR * Next;
}IP_ADDR;
@ -115,6 +116,7 @@ INT GetSelectedItem(HWND hDlgCtrl);
HRESULT InitializeTcpipBasicDlgCtrls(HWND hwndDlg, TcpipSettings * pCurSettings);
VOID InsertColumnToListView(HWND hDlgCtrl, UINT ResId, UINT SubItem, UINT Size);
INT_PTR StoreTcpipBasicSettings(HWND hwndDlg, TcpipConfNotifyImpl * This, BOOL bApply);
HRESULT Initialize(TcpipConfNotifyImpl * This);
VOID
DisplayError(UINT ResTxt, UINT ResTitle, UINT Type)
@ -2373,6 +2375,7 @@ CopyIpAddrString(
if (Type == SUBMASK)
{
pNew->u.Subnetmask = GetIpAddressFromStringA(pCurrent->IpMask.String);
pNew->NTEContext = pCurrent->Context;
}
else if (Type == METRIC)
{
@ -2632,6 +2635,7 @@ LoadDNSSettings(
HKEY hKey;
DWORD dwSize;
This->pCurrentConfig->pDNS = (TcpipAdvancedDNSDlgSettings*) CoTaskMemAlloc(sizeof(TcpipAdvancedDNSDlgSettings));
if (!This->pCurrentConfig->pDNS)
return E_FAIL;
@ -2748,7 +2752,7 @@ LoadFilterSettings(
HRESULT
InitializeTcpipBasicDlg(TcpipConfNotifyImpl * This)
Initialize(TcpipConfNotifyImpl * This)
{
DWORD dwSize;
WCHAR szBuffer[50];
@ -2876,7 +2880,7 @@ INetCfgComponentPropertyUi_fnMergePropPages(
HRESULT hr;
TcpipConfNotifyImpl * This = (TcpipConfNotifyImpl*)iface;
hr = InitializeTcpipBasicDlg(This);
hr = Initialize(This);
if (FAILED(hr))
return hr;
@ -3092,24 +3096,37 @@ INetCfgComponentControl_fnApplyRegistryChanges(
LPOLESTR pStr;
DWORD dwSize;
WCHAR szBuffer[200];
TcpipSettings * pCurrentConfig, *pOldConfig;
ULONG NTEInstance;
TcpipConfNotifyImpl * This = impl_from_INetCfgComponentControl(iface);
pCurrentConfig = This->pCurrentConfig;
This->pCurrentConfig = NULL;
if (FAILED(Initialize(This)))
{
This->pCurrentConfig = pCurrentConfig;
return E_FAIL;
}
pOldConfig = This->pCurrentConfig;
This->pCurrentConfig = pCurrentConfig;
//MessageBoxW(NULL, L"INetCfgComponentControl_fnApplyRegistryChanges", NULL, MB_OK);
if (RegCreateKeyExW(hKey, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
{
if (This->pCurrentConfig->pDNS)
if (pCurrentConfig->pDNS)
{
RegSetValueExW(hKey, L"UseDomainNameDevolution", 0, REG_DWORD, (LPBYTE)&This->pCurrentConfig->pDNS->UseDomainNameDevolution, sizeof(DWORD));
RegSetValueExW(hKey, L"SearchList", 0, REG_SZ, (LPBYTE)This->pCurrentConfig->pDNS->szSearchList,
(wcslen(This->pCurrentConfig->pDNS->szSearchList)+1) * sizeof(WCHAR));
RegSetValueExW(hKey, L"UseDomainNameDevolution", 0, REG_DWORD, (LPBYTE)&pCurrentConfig->pDNS->UseDomainNameDevolution, sizeof(DWORD));
RegSetValueExW(hKey, L"SearchList", 0, REG_SZ, (LPBYTE)pCurrentConfig->pDNS->szSearchList,
(wcslen(pCurrentConfig->pDNS->szSearchList)+1) * sizeof(WCHAR));
}
if (This->pCurrentConfig->pFilter)
if (pCurrentConfig->pFilter)
{
RegSetValueExW(hKey, L"EnableSecurityFilters", 0, REG_DWORD,
(LPBYTE)&This->pCurrentConfig->pFilter->EnableSecurityFilters, sizeof(DWORD));
(LPBYTE)&pCurrentConfig->pFilter->EnableSecurityFilters, sizeof(DWORD));
}
RegCloseKey(hKey);
}
@ -3122,7 +3139,7 @@ INetCfgComponentControl_fnApplyRegistryChanges(
if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szBuffer, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
{
if (This->pCurrentConfig->pDNS)
if (pCurrentConfig->pDNS)
{
RegSetValueExW(hKey, L"RegisterAdapterName", 0, REG_DWORD, (LPBYTE)&This->pCurrentConfig->pDNS->RegisterAdapterName, sizeof(DWORD));
RegSetValueExW(hKey, L"RegistrationEnabled", 0, REG_DWORD, (LPBYTE)&This->pCurrentConfig->pDNS->RegistrationEnabled, sizeof(DWORD));
@ -3130,60 +3147,78 @@ INetCfgComponentControl_fnApplyRegistryChanges(
(wcslen(This->pCurrentConfig->pDNS->szDomain)+1) * sizeof(WCHAR));
}
#if 0
if (This->pCurrentConfig->pFilter)
if (pCurrentConfig->pFilter)
{
if (This->pCurrentConfig->pFilter->szTCPAllowedPorts)
if (pCurrentConfig->pFilter->szTCPAllowedPorts)
{
RegSetValueExW(hKey, L"TCPAllowedPorts", 0, REG_MULTI_SZ,
(LPBYTE)This->pCurrentConfig->pFilter->szTCPAllowedPorts,
This->pCurrentConfig->pFilter->TCPSize);
(LPBYTE)pCurrentConfig->pFilter->szTCPAllowedPorts,
pCurrentConfig->pFilter->TCPSize);
}
if (This->pCurrentConfig->pFilter->szUDPAllowedPorts)
if (pCurrentConfig->pFilter->szUDPAllowedPorts)
{
RegSetValueExW(hKey, L"UDPAllowedPorts", 0, REG_MULTI_SZ,
(LPBYTE)This->pCurrentConfig->pFilter->szUDPAllowedPorts,
This->pCurrentConfig->pFilter->UDPSize);
(LPBYTE)pCurrentConfig->pFilter->szUDPAllowedPorts,
pCurrentConfig->pFilter->UDPSize);
}
if (This->pCurrentConfig->pFilter->szRawIPAllowedProtocols)
if (pCurrentConfig->pFilter->szRawIPAllowedProtocols)
{
RegSetValueExW(hKey, L"RawIPAllowedProtocols", 0, REG_MULTI_SZ,
(LPBYTE)This->pCurrentConfig->pFilter->szRawIPAllowedProtocols,
This->pCurrentConfig->pFilter->IPSize);
(LPBYTE)pCurrentConfig->pFilter->szRawIPAllowedProtocols,
pCurrentConfig->pFilter->IPSize);
}
}
#endif
RegSetValueExW(hKey, L"EnableDHCP", 0, REG_DWORD, (LPBYTE)&This->pCurrentConfig->DhcpEnabled, sizeof(DWORD));
if (This->pCurrentConfig->DhcpEnabled)
RegSetValueExW(hKey, L"EnableDHCP", 0, REG_DWORD, (LPBYTE)&pCurrentConfig->DhcpEnabled, sizeof(DWORD));
if (pCurrentConfig->DhcpEnabled)
{
RegSetValueExW(hKey, L"IPAddress", 0, REG_MULTI_SZ, (LPBYTE)L"0.0.0.0\0", 9 * sizeof(WCHAR));
RegSetValueExW(hKey, L"SubnetMask", 0, REG_MULTI_SZ, (LPBYTE)L"0.0.0.0\0", 9 * sizeof(WCHAR));
RegSetValueExW(hKey, L"DefaultGateway", 0, REG_MULTI_SZ, (LPBYTE)L"\0", 2 * sizeof(WCHAR));
RegSetValueExW(hKey, L"DefaultGatewayMetric", 0, REG_MULTI_SZ, (LPBYTE)L"\0", 2 * sizeof(WCHAR));
if (!pOldConfig->DhcpEnabled)
{
DeleteIPAddress(pOldConfig->Ip->NTEContext);
//FIXME
// start dhcp client service for the adapter
}
}
else
{
pStr = CreateMultiSzString(This->pCurrentConfig->Ip, IPADDR, &dwSize, FALSE);
if (!pOldConfig->DhcpEnabled)
{
DeleteIPAddress(pOldConfig->Ip->NTEContext);
//TODO
//delete multiple ip addresses when required
}
//TODO
// add multiple ip addresses when required
if (AddIPAddress(pCurrentConfig->Ip->IpAddress, pCurrentConfig->Ip->u.Subnetmask, pCurrentConfig->Index, &pCurrentConfig->Ip->NTEContext, &NTEInstance) == NO_ERROR)
{
pStr = CreateMultiSzString(pCurrentConfig->Ip, IPADDR, &dwSize, FALSE);
if(pStr)
{
RegSetValueExW(hKey, L"IPAddress", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
CoTaskMemFree(pStr);
}
pStr = CreateMultiSzString(This->pCurrentConfig->Ip, SUBMASK, &dwSize, FALSE);
pStr = CreateMultiSzString(pCurrentConfig->Ip, SUBMASK, &dwSize, FALSE);
if(pStr)
{
RegSetValueExW(hKey, L"SubnetMask", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
CoTaskMemFree(pStr);
}
}
pStr = CreateMultiSzString(This->pCurrentConfig->Gw, IPADDR, &dwSize, FALSE);
pStr = CreateMultiSzString(pCurrentConfig->Gw, IPADDR, &dwSize, FALSE);
if(pStr)
{
RegSetValueExW(hKey, L"DefaultGateway", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
CoTaskMemFree(pStr);
}
pStr = CreateMultiSzString(This->pCurrentConfig->Gw, METRIC, &dwSize, FALSE);
pStr = CreateMultiSzString(pCurrentConfig->Gw, METRIC, &dwSize, FALSE);
if(pStr)
{
RegSetValueExW(hKey, L"DefaultGatewayMetric", 0, REG_MULTI_SZ, (LPBYTE)pStr, dwSize);
@ -3191,13 +3226,13 @@ INetCfgComponentControl_fnApplyRegistryChanges(
}
}
if (!This->pCurrentConfig->Ns || This->pCurrentConfig->AutoconfigActive)
if (!pCurrentConfig->Ns || pCurrentConfig->AutoconfigActive)
{
RegSetValueExW(hKey, L"NameServer", 0, REG_SZ, (LPBYTE)L"", 1 * sizeof(WCHAR));
}
else
{
pStr = CreateMultiSzString(This->pCurrentConfig->Ns, IPADDR, &dwSize, TRUE);
pStr = CreateMultiSzString(pCurrentConfig->Ns, IPADDR, &dwSize, TRUE);
if(pStr)
{
RegSetValueExW(hKey, L"NameServer", 0, REG_SZ, (LPBYTE)pStr, dwSize);
@ -3208,7 +3243,6 @@ INetCfgComponentControl_fnApplyRegistryChanges(
RegCloseKey(hKey);
}
return S_OK;
}