Source code of Windows XP (NT5)
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.

267 lines
8.7 KiB

  1. // nat access objects
  2. class CNATNode;
  3. class CNATSiteComputer;
  4. class CNATSite;
  5. class CNATGroup;
  6. class CNATServerComputer;
  7. // a list of group types. To be used to show an appropriate icon
  8. enum {
  9. GROUP_TYPE_WWW = 0,
  10. GROUP_TYPE_FTP,
  11. GROUP_TYPE_MAIL,
  12. GROUP_TYPE_UNKNOWN = 0XFFFFFFFF
  13. };
  14. #define HASH_BYTE_SIZE 16
  15. //---------------------------------------------------------------------------------
  16. // virtual abstract class just used to get that OnProperties on the virutal table
  17. class CNATNode : public CObject
  18. {
  19. public:
  20. // Edit the properties of this Site - true if OK
  21. virtual BOOL OnProperties() = 0;
  22. };
  23. //---------------------------------------------------------------------------------
  24. class CNATSiteComputer : public CObject
  25. {
  26. public:
  27. CNATSiteComputer( LPCTSTR pszName, BOOL fVisible = TRUE ):
  28. m_fVisibleOnNet(fVisible),
  29. m_iComp(0),
  30. m_refcount(0)
  31. {
  32. m_csName = pszName;
  33. }
  34. ~CNATSiteComputer() {;}
  35. // ref counting
  36. void AddRef() {m_refcount++;}
  37. void RemoveRef() {m_refcount--;}
  38. // When added by a refresh, the visibility of the computer is checked on the
  39. // net. This flag indicates whether or not that check suceeded.
  40. BOOL m_fVisibleOnNet;
  41. // the network name of the machine
  42. CString m_csName;
  43. // internal DWORD used only during the machine committing process
  44. DWORD m_iComp;
  45. // internal ref count to see how many sites point to it
  46. DWORD m_refcount;
  47. };
  48. //---------------------------------------------------------------------------------
  49. // coded in natobjs.cpp
  50. class CNATSite : public CNATNode
  51. {
  52. public:
  53. CNATSite(CNATGroup* pGroup, CNATSiteComputer* pSiteComputer,
  54. LPCTSTR pszPrivateIP = _T(""),
  55. LPCTSTR pszName = _T(""));
  56. ~CNATSite(); // don't forget to decrement the refcount
  57. // Edit the properties of this Site - true if OK
  58. BOOL OnProperties();
  59. // get the data associated with the group
  60. void GetIP( OUT CString &csIP ) { csIP = m_csPrivateIP; }
  61. LPCTSTR GetIP() { return (LPCTSTR)m_csPrivateIP; }
  62. void GetName( OUT CString &csName ) { csName = m_csName; }
  63. LPCTSTR GetName() { return (LPCTSTR)m_csName; }
  64. // reference to the computer object this site relates to
  65. CNATSiteComputer* m_pSiteComputer;
  66. // the private IP this site relates to
  67. CString m_csPrivateIP;
  68. // the name (friendly) this site relates to
  69. CString m_csName;
  70. // the owning CNATGroup
  71. CNATGroup* m_pGroup;
  72. };
  73. //---------------------------------------------------------------------------------
  74. // coded in natgroup.cpp
  75. class CNATGroup : public CNATNode
  76. {
  77. public:
  78. CNATGroup( CNATServerComputer* pNatComputer, LPCTSTR pszIP = _T(""),
  79. LPCTSTR pszName = _T(""), DWORD dwSticky = 0, DWORD type = GROUP_TYPE_UNKNOWN );
  80. ~CNATGroup();
  81. // Edit the properties of this Site - true if OK
  82. BOOL OnProperties();
  83. // This is just a handy way to get the nat machine object to commit
  84. void Commit();
  85. // get the data associated with the group
  86. void GetIP( OUT CString &csIP ) { csIP = m_csIP; }
  87. LPCTSTR GetIP() { return (LPCTSTR)m_csIP; }
  88. void GetName( OUT CString &csName ) { csName = m_csName; }
  89. LPCTSTR GetName() { return (LPCTSTR)m_csName; }
  90. void GetSticky( OUT DWORD* pdwSticky ) { *pdwSticky = m_dwSticky; }
  91. DWORD GetSticky() { return m_dwSticky; }
  92. void GetType( OUT DWORD* pdwType ) { *pdwType = m_type; }
  93. DWORD GetType() { return m_type; }
  94. // get the number of groups associated with this machine
  95. DWORD GetNumSites() {return m_rgbSites.GetSize();}
  96. // Get a Site referece
  97. CNATSite* GetSite( IN DWORD iSite ) {return m_rgbSites[iSite];}
  98. // adds a new site to the list.
  99. CNATSite* NewSite();
  100. // adds an existing site to the list - to be called during a refresh.
  101. // this checks the visiblity of the machine on the net as it adds it
  102. void AddSite( IN CNATSiteComputer* pSiteComputer, IN LPCTSTR pszPrivateIP, IN LPCTSTR pszName );
  103. protected:
  104. // empties and frees all the groups/sites in the groups list
  105. void EmptySites();
  106. // this is the owning NATMachine object. All the real action takes place there.
  107. CNATServerComputer* m_pNatComputer;
  108. // a dynamic array of the sites assocated with the group
  109. CTypedPtrArray<CObArray, CNATSite*> m_rgbSites;
  110. // the string that represents the public IP/Port pair presented by the group
  111. CString m_csIP;
  112. // the string that represents the friendly name of the group
  113. CString m_csName;
  114. // the DWORD that represents the sticky IP timeout of the group
  115. DWORD m_dwSticky;
  116. // DWORD indicating what type of group this is.
  117. DWORD m_type;
  118. };
  119. //---------------------------------------------------------------------------------
  120. // coded in NATServerComputer.cpp
  121. class CNATServerComputer : public CNATNode
  122. {
  123. public:
  124. CNATServerComputer( LPCTSTR pszComputerName );
  125. ~CNATServerComputer();
  126. // rebuild all the data based on a new blob from the NAT machine
  127. void Refresh();
  128. // commit the current state of the data back to the NAT machine
  129. void Commit();
  130. // Edit the properties of this Site - true if OK
  131. BOOL OnProperties();
  132. // add a new group to the server computer (called by the UI). This
  133. // may or may not prompt the user with UI and returns the pointer
  134. // to the new group after adding it to the group list
  135. CNATGroup* NewGroup();
  136. // add a new computer to the sites list. - Note: if the computer
  137. // already exists in the sites list, it will just return a reference
  138. // to the existing computer. This routine prompts the user to choose
  139. // a computer to add. Returns FALSE if it fails.
  140. CNATSiteComputer* NewComputer();
  141. // get the number of groups associated with this machine
  142. DWORD GetNumGroups();
  143. // Get a group reference
  144. CNATGroup* GetGroup( IN DWORD iGroup );
  145. // Technically, the GetGroupName function is unecessary because
  146. // you get get the group class pointer, then call GetName on it, but it is really
  147. // handy to just do it here. Cleans up the snapin part of the code.
  148. BOOL GetGroupName( IN DWORD iGroup, OUT CString &csName );
  149. // call this to automatically verify that the target NAT computers config info
  150. // hasn't changed. If it has, it prompts the user and lets them continue or refresh.
  151. BOOL VerifyHashIsOK();
  152. protected:
  153. // utility to check if the computer is visible on the net
  154. BOOL CanSeeComputer( IN LPCTSTR pszname );
  155. // empties and frees all the site computer objects in the list
  156. void EmptySiteComputers();
  157. // empties and frees all the groups/sites in the groups list
  158. void EmptyGroups();
  159. // adds an existing computer to the list - to be called during a refresh.
  160. // this checks the visiblity of the machine on the net as it adds it
  161. void AddSiteComputer( IN LPWSTR pszwName );
  162. // adds an existing group to the list - to be called during a refresh.
  163. void AddGroup( IN LPWSTR pszwIPPublic, IN LPWSTR pszwName, IN DWORD dwSticky, IN DWORD type );
  164. // gets the crypto hash of the NAT data blob. If a null pointer to the blob
  165. // is passed in, then it dynamically gets the blob from the server
  166. // or you can pass in a specific blob. This is to be used to check if
  167. // the state of the server has changed since the data was last loaded.
  168. // The hash is obtained from the crypto code so it is really good. The
  169. // buffer for the hash should be 128 bits in length. Using an MD5 hash.
  170. BOOL GetNATStateHash( IN LPBYTE pData, IN DWORD cbData, IN OUT LPBYTE pHash, OUT DWORD* pcbHash );
  171. // access the server and retrieve the state blob. Use GetLastError to see
  172. // what went wrong if the returned result is NULL. Pass in the dword pointed
  173. // to by pcbData to get the required size.
  174. LPBYTE PGetNATStateBlob( OUT DWORD* pcbData );
  175. // access the server and set the state blob. Use GetLastError to see what went
  176. // wrong if the returned result is FALSE
  177. BOOL SetStateBlob( IN LPBYTE pData, IN DWORD cbData );
  178. // open the DCOM interface to the target NAT machine.
  179. HRESULT GetNATInterface( OUT IMSIisLb** ppIisLb );
  180. // the name of the target NAT machine to edit
  181. CString m_csNatComputer;
  182. // an dynamic array of the groups associated with the NAT machine
  183. CTypedPtrArray<CObArray, CNATGroup*> m_rgbGroups;
  184. // a dynamic array of the site computers assocated with the NAT machine
  185. CTypedPtrArray<CObArray, CNATSiteComputer*> m_rgbSiteComputers;
  186. // the last refresh hash of the config blob
  187. BYTE m_hash[HASH_BYTE_SIZE];
  188. };