Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
3.8 KiB

  1. //============================================================================
  2. // Copyright(c) 1996, Microsoft Corporation
  3. //
  4. // File: ipcfg.cpp
  5. //
  6. // History:
  7. // 08/30/96 Ram Cherala Created
  8. //
  9. // Implementation of IP Packet Filters Configuration
  10. //============================================================================
  11. #include "stdafx.h"
  12. #include "rtrfiltr.h"
  13. #include "ipfltr.h"
  14. #include "format.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. //-----------------------------------------------------------------------------
  21. // Function: IpFilterConfig
  22. //
  23. // Handles connecting to router, getting interface info, creating the IP filter
  24. // configuration dialog and saving the Filters back to the registry.
  25. // Uses CRouterInfo and other classes implemented in ..\common library.
  26. //------------------------------------------------------------------------------
  27. DWORD APIENTRY
  28. IpFilterConfig(
  29. IN CWnd* pParent,
  30. IN LPCWSTR pwsMachineName,
  31. IN LPCWSTR pwsInterfaceName,
  32. IN DWORD dwFilterType // FILTER_INBOUND, FILTER_OUTBOUND
  33. ) {
  34. DWORD dwErr;
  35. HANDLE hMprConfig = NULL, hInterface = NULL, hIfTransport = NULL;
  36. TCHAR* pszMachine;
  37. SPIRouterInfo spRouterInfo;
  38. SPIRtrMgrInterfaceInfo spRmIf;
  39. SPIInfoBase spInfoBase;
  40. HRESULT hr = hrOK;
  41. //
  42. // Convert the machine name from Unicode
  43. //
  44. if (!pwsMachineName) { pszMachine = NULL; }
  45. else {
  46. pszMachine = (TCHAR *) alloca((StrLenW(pwsMachineName)+3) * sizeof(TCHAR));
  47. StrCpyTFromW(pszMachine, pwsMachineName);
  48. }
  49. // Connect to the server first
  50. dwErr = ::MprConfigServerConnect((LPWSTR)pwsMachineName, &hMprConfig);
  51. if (dwErr != NO_ERROR) { return dwErr; }
  52. // create a CRouterInfo object
  53. CreateRouterInfo(&spRouterInfo, NULL, pwsMachineName);
  54. CWaitCursor wait;
  55. // Now load the RouterInfo data from the registry
  56. hr = spRouterInfo->Load((LPCTSTR)pszMachine, hMprConfig);
  57. if (!FHrSucceeded(hr)) { return WIN32_FROM_HRESULT(hr); }
  58. // Get the pointer to the CRmInterfaceInfo object for the specified
  59. // protocol and interface
  60. LookupRtrMgrInterface(spRouterInfo,
  61. pwsInterfaceName,
  62. PID_IP,
  63. &spRmIf);
  64. if (!spRmIf) { return ERROR_INVALID_DATA ;}
  65. // Load the data for the specified interface
  66. hr = spRmIf->Load(pszMachine, hMprConfig, NULL, NULL);
  67. if (!FHrSucceeded(hr))
  68. return WIN32_FROM_HRESULT(hr);
  69. spRmIf->GetInfoBase(hMprConfig, NULL, NULL, &spInfoBase);
  70. //
  71. // Display the IP filter configuration dialog
  72. //
  73. if (IpFilterConfigInfoBase(pParent->GetSafeHwnd(),
  74. spInfoBase,
  75. spRmIf,
  76. dwFilterType) == hrOK)
  77. {
  78. hr = spRmIf->Save(pszMachine,
  79. hMprConfig,
  80. NULL,
  81. NULL,
  82. spInfoBase,
  83. 0);
  84. if (FHrSucceeded(hr))
  85. dwErr = ERROR_SUCCESS;
  86. else
  87. dwErr = WIN32_FROM_HRESULT(hr);
  88. }
  89. //
  90. //
  91. //
  92. // do clean up here and return
  93. //
  94. ::MprConfigServerDisconnect( hMprConfig );
  95. return dwErr;
  96. }
  97. HRESULT APIENTRY
  98. IpFilterConfigInfoBase(
  99. IN HWND hwndParent,
  100. IN IInfoBase * pInfoBase,
  101. IN IRtrMgrInterfaceInfo *pRmIf,
  102. IN DWORD dwFilterType // FILTER_INBOUND, FILTER_OUTBOUND
  103. ) {
  104. HRESULT hr = hrOK;
  105. if (dwFilterType == FILTER_DEMAND_DIAL)
  106. {
  107. //
  108. // Display the IP filter configuration dialog
  109. //
  110. CIpFltrDD dlg(CWnd::FromHandle(hwndParent), pInfoBase, dwFilterType );
  111. if (dlg.DoModal() == IDOK)
  112. hr = hrOK;
  113. else
  114. hr = hrFalse;
  115. }
  116. else
  117. {
  118. //
  119. // Display the IP filter configuration dialog
  120. //
  121. CIpFltr dlg(CWnd::FromHandle(hwndParent), pInfoBase, dwFilterType );
  122. if (dlg.DoModal() == IDOK)
  123. hr = hrOK;
  124. else
  125. hr = hrFalse;
  126. }
  127. return hr;
  128. }