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.

189 lines
4.8 KiB

  1. #pragma once
  2. #include <ipnatapi.h>
  3. #include <rasuip.h>
  4. /////////////////////////////////////////////////////////////////////////////
  5. // CNat
  6. class ATL_NO_VTABLE CNat :
  7. public CComObjectRootEx<CComMultiThreadModel>,
  8. public INat
  9. {
  10. public:
  11. CNat()
  12. {
  13. m_hTranslatorHandle = NULL;
  14. m_pSidLocalService = NULL;
  15. m_pSidLocalSystem = NULL;
  16. }
  17. virtual ~CNat();
  18. DECLARE_NO_REGISTRY()
  19. DECLARE_NOT_AGGREGATABLE(CNat)
  20. BEGIN_COM_MAP(CNat)
  21. COM_INTERFACE_ENTRY(INat)
  22. END_COM_MAP()
  23. //
  24. // INat
  25. //
  26. public:
  27. STDMETHODIMP CreateDynamicRedirect(
  28. IN ULONG Flags,
  29. IN ULONG AdapterIndex,
  30. IN UCHAR Protocol,
  31. IN ULONG DestinationAddress,
  32. IN USHORT DestinationPort,
  33. IN ULONG SourceAddress,
  34. IN USHORT SourcePort,
  35. IN ULONG NewDestinationAddress,
  36. IN USHORT NewDestinationPort,
  37. IN ULONG NewSourceAddress,
  38. IN USHORT NewSourcePort,
  39. OUT HANDLE_PTR* DynamicRedirectHandle
  40. );
  41. STDMETHOD(CancelDynamicRedirect)(
  42. HANDLE_PTR DynamicRedirectHandle
  43. );
  44. STDMETHODIMP CreateRedirect(
  45. IN ULONG nFlags,
  46. IN UCHAR Protocol,
  47. IN ULONG nDestinationAddress,
  48. IN USHORT nDestinationPort,
  49. IN ULONG nSourceAddress,
  50. IN USHORT nSourcePort,
  51. IN ULONG nNewDestinationAddress,
  52. IN USHORT nNewDestinationPort,
  53. IN ULONG nNewSourceAddress,
  54. IN USHORT nNewSourcePort,
  55. IN ULONG nRestrictAdapterIndex,
  56. IN DWORD_PTR dwAlgProcessId,
  57. IN HANDLE_PTR hEventForCreate,
  58. IN HANDLE_PTR hEventForDelete
  59. );
  60. STDMETHODIMP CancelRedirect(
  61. IN UCHAR Protocol,
  62. IN ULONG nDestinationAddress,
  63. IN USHORT nDestinationPort,
  64. IN ULONG nSourceAddress,
  65. IN USHORT nSourcePort,
  66. IN ULONG nNewDestinationAddress,
  67. IN USHORT nNewDestinationPort,
  68. IN ULONG nNewSourceAddress,
  69. IN USHORT nNewSourcePort
  70. );
  71. STDMETHODIMP
  72. GetBestSourceAddressForDestinationAddress(
  73. IN ULONG ulDestinationAddress,
  74. IN BOOL fDemandDial,
  75. OUT ULONG* pulBestSrcAddress
  76. );
  77. STDMETHODIMP CNat::LookupAdapterPortMapping(
  78. IN ULONG ulAdapterIndex,
  79. IN UCHAR Protocol,
  80. IN ULONG ulDestinationAddress,
  81. IN USHORT usDestinationPort,
  82. OUT ULONG* pulRemapAddress,
  83. OUT USHORT* pusRemapPort
  84. );
  85. STDMETHODIMP GetOriginalDestinationInformation(
  86. IN UCHAR Protocol,
  87. IN ULONG nDestinationAddress,
  88. IN USHORT nDestinationPort,
  89. IN ULONG nSourceAddress,
  90. IN USHORT nSourcePort,
  91. OUT ULONG* pnOriginalDestinationAddress,
  92. OUT USHORT* pnOriginalDestinationPort,
  93. OUT ULONG* pulAdapterIndex
  94. );
  95. STDMETHODIMP ReleasePort(
  96. IN USHORT ReservedPortBase,
  97. IN USHORT PortCount
  98. );
  99. STDMETHODIMP ReservePort(
  100. IN USHORT PortCount,
  101. OUT PUSHORT ReservedPortBase
  102. );
  103. private:
  104. //
  105. // ALG expose publicly eAGL_TCP=1 and eALG_UP=2 and intenaly UDP is 0x11 and TCP is 0x06
  106. //
  107. inline UCHAR
  108. ProtocolConvertToNT(
  109. UCHAR Protocol
  110. )
  111. {
  112. if ( Protocol== eALG_TCP )
  113. return NAT_PROTOCOL_TCP;
  114. if ( Protocol== eALG_UDP )
  115. return NAT_PROTOCOL_UDP;
  116. return Protocol;
  117. }
  118. //
  119. // Properties
  120. //
  121. private:
  122. HANDLE m_hTranslatorHandle;
  123. CComAutoCriticalSection m_AutoCS_SIDAllocation;
  124. PSID m_pSidLocalService;
  125. PSID m_pSidLocalSystem;
  126. CComAutoCriticalSection m_AutoCS_DynamicRedirect;
  127. CSimpleArray<HANDLE_PTR> m_ListOfOutstandingRedirects;
  128. //
  129. // Helper private Methods
  130. //
  131. inline HANDLE GetTranslatorHandle()
  132. {
  133. if ( !m_hTranslatorHandle )
  134. {
  135. LRESULT lRet = NatInitializeTranslator(&m_hTranslatorHandle);
  136. if ( ERROR_SUCCESS != lRet )
  137. return NULL;
  138. }
  139. return m_hTranslatorHandle;
  140. }
  141. bool
  142. IsTokenPartOfWellKnowSid(
  143. HANDLE pTokenToCheck,
  144. WELL_KNOWN_SID_TYPE WellKnownSidToCheckAgainst,
  145. PSID& pSidToCache
  146. );
  147. bool IsClientAllowedToCallUs();
  148. };