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.

336 lines
7.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: U I I N F O . C P P
  7. //
  8. // Contents: Implements a call-back COM object used to raise properties
  9. // on INetCfg components. This object implements the
  10. // INetRasConnectionIpUiInfo interface.
  11. //
  12. // Notes:
  13. //
  14. // Author: shaunco 1 Jan 1998
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "rasdlgp.h"
  18. #include "netconp.h"
  19. #include "uiinfo.h"
  20. class CRasConnectionUiIpInfo :
  21. public INetRasConnectionIpUiInfo
  22. {
  23. private:
  24. ULONG m_cRef;
  25. PEINFO* m_pInfo;
  26. friend
  27. void
  28. RevokePeinfoFromUiInfoCallbackObject (
  29. IUnknown* punk);
  30. public:
  31. CRasConnectionUiIpInfo (PEINFO* pInfo);
  32. // IUnknown
  33. //
  34. STDMETHOD (QueryInterface) (REFIID riid, void** ppv);
  35. STDMETHOD_(ULONG, AddRef) (void);
  36. STDMETHOD_(ULONG, Release) (void);
  37. // INetRasConnectionIpUiInfo
  38. //
  39. STDMETHOD (GetUiInfo) (RASCON_IPUI* pIpui);
  40. };
  41. // Constructor. Set our reference count to 1 and initialize our members.
  42. //
  43. CRasConnectionUiIpInfo::CRasConnectionUiIpInfo (
  44. PEINFO* pInfo)
  45. {
  46. m_cRef = 1;
  47. m_pInfo = pInfo;
  48. }
  49. // IUnknown
  50. //
  51. STDMETHODIMP
  52. CRasConnectionUiIpInfo::QueryInterface (
  53. REFIID riid,
  54. void** ppv)
  55. {
  56. static const IID IID_INetRasConnectionIpUiInfo =
  57. {0xFAEDCF58,0x31FE,0x11D1,{0xAA,0xD2,0x00,0x80,0x5F,0xC1,0x27,0x0E}};
  58. if (!ppv)
  59. {
  60. return E_POINTER;
  61. }
  62. if ((IID_IUnknown == riid) ||
  63. (IID_INetRasConnectionIpUiInfo == riid))
  64. {
  65. *ppv = static_cast<void*>(static_cast<IUnknown*>(this));
  66. AddRef ();
  67. return S_OK;
  68. }
  69. *ppv = NULL;
  70. return E_NOINTERFACE;
  71. }
  72. // Standard AddRef and Release implementations.
  73. //
  74. STDMETHODIMP_(ULONG)
  75. CRasConnectionUiIpInfo::AddRef (void)
  76. {
  77. return ++m_cRef;
  78. }
  79. STDMETHODIMP_(ULONG)
  80. CRasConnectionUiIpInfo::Release (void)
  81. {
  82. ULONG cRef = --m_cRef;
  83. if (0 == cRef)
  84. {
  85. delete this;
  86. }
  87. return cRef;
  88. }
  89. // INetRasConnectionIpUiInfo
  90. //
  91. STDMETHODIMP
  92. CRasConnectionUiIpInfo::GetUiInfo (
  93. RASCON_IPUI* pIpui)
  94. {
  95. // Validate parameters.
  96. //
  97. if (!pIpui)
  98. {
  99. return E_POINTER;
  100. }
  101. ZeroMemory (pIpui, sizeof(*pIpui));
  102. // We need to have a PEINFO with which to answer the call.
  103. // If it was revoked, it means we're being called after everything
  104. // has gone away. (The caller probably has not released us when he
  105. // he should have.)
  106. //
  107. if (!m_pInfo)
  108. {
  109. return E_UNEXPECTED;
  110. }
  111. PBENTRY* pEntry = m_pInfo->pArgs->pEntry;
  112. // Phonebook upgrade code needs to assure that pGuid is always present.
  113. //
  114. pIpui->guidConnection = *pEntry->pGuid;
  115. // Set whether its SLIP or PPP.
  116. //
  117. if (BP_Slip == pEntry->dwBaseProtocol)
  118. {
  119. pIpui->dwFlags = RCUIF_SLIP;
  120. }
  121. else
  122. {
  123. pIpui->dwFlags = RCUIF_PPP;
  124. }
  125. // Set whether this is demand dial or not
  126. //
  127. if (m_pInfo->pArgs->fRouter)
  128. {
  129. pIpui->dwFlags |= RCUIF_DEMAND_DIAL;
  130. }
  131. // Set whether we're in non-admin mode (406630)
  132. //
  133. if (m_pInfo->fNonAdmin)
  134. {
  135. pIpui->dwFlags |= RCUIF_NOT_ADMIN;
  136. }
  137. // !!! This is temporary and can be removed when this flag has been added to
  138. // the checked in necomp IDL file.
  139. //
  140. #ifndef RCUIF_VPN
  141. #define RCUIF_VPN 0x40
  142. #endif
  143. // Note if it's a VPN connection.
  144. //
  145. if (pEntry->dwType == RASET_Vpn)
  146. {
  147. pIpui->dwFlags |= RCUIF_VPN;
  148. }
  149. // Set whether to use a specific IP address.
  150. //
  151. // Whistler bug 304064 NT4SLIP connection gets wrong IP settings on upgrade
  152. //
  153. if (pEntry->pszIpAddress &&
  154. ((BP_Slip == pEntry->dwBaseProtocol) ||
  155. (ASRC_RequireSpecific == pEntry->dwIpAddressSource)))
  156. {
  157. pIpui->dwFlags |= RCUIF_USE_IP_ADDR;
  158. if (pEntry->pszIpAddress &&
  159. lstrcmp(pEntry->pszIpAddress, TEXT("0.0.0.0")))
  160. {
  161. lstrcpynW (
  162. pIpui->pszwIpAddr,
  163. pEntry->pszIpAddress,
  164. sizeof(pIpui->pszwIpAddr) / sizeof(WCHAR));
  165. }
  166. }
  167. // Set whether to use specific name server addresses.
  168. //
  169. // Whistler bug 304064 NT4SLIP connection gets wrong IP settings on upgrade
  170. //
  171. if (((BP_Slip == pEntry->dwBaseProtocol) ||
  172. (ASRC_RequireSpecific == pEntry->dwIpNameSource)) &&
  173. (pEntry->pszIpDnsAddress || pEntry->pszIpDns2Address ||
  174. pEntry->pszIpWinsAddress || pEntry->pszIpWins2Address))
  175. {
  176. pIpui->dwFlags |= RCUIF_USE_NAME_SERVERS;
  177. // Since the phonebook stores zeros even for unused IP address
  178. // strings, we need to ignore them explicitly.
  179. //
  180. if (pEntry->pszIpDnsAddress &&
  181. lstrcmp(pEntry->pszIpDnsAddress, TEXT("0.0.0.0")))
  182. {
  183. lstrcpynW (
  184. pIpui->pszwDnsAddr,
  185. pEntry->pszIpDnsAddress,
  186. sizeof(pIpui->pszwDnsAddr) / sizeof(WCHAR));
  187. }
  188. if (pEntry->pszIpDns2Address &&
  189. lstrcmp(pEntry->pszIpDns2Address, TEXT("0.0.0.0")))
  190. {
  191. lstrcpynW (
  192. pIpui->pszwDns2Addr,
  193. pEntry->pszIpDns2Address,
  194. sizeof(pIpui->pszwDns2Addr) / sizeof(WCHAR));
  195. }
  196. if (pEntry->pszIpWinsAddress &&
  197. lstrcmp(pEntry->pszIpWinsAddress, TEXT("0.0.0.0")))
  198. {
  199. lstrcpynW (
  200. pIpui->pszwWinsAddr,
  201. pEntry->pszIpWinsAddress,
  202. sizeof(pIpui->pszwWinsAddr) / sizeof(WCHAR));
  203. }
  204. if (pEntry->pszIpWins2Address &&
  205. lstrcmp(pEntry->pszIpWins2Address, TEXT("0.0.0.0")))
  206. {
  207. lstrcpynW (
  208. pIpui->pszwWins2Addr,
  209. pEntry->pszIpWins2Address,
  210. sizeof(pIpui->pszwWins2Addr) / sizeof(WCHAR));
  211. }
  212. }
  213. if (!m_pInfo->pArgs->fRouter && pEntry->fIpPrioritizeRemote)
  214. {
  215. pIpui->dwFlags |= RCUIF_USE_REMOTE_GATEWAY;
  216. }
  217. if (pEntry->fIpHeaderCompression)
  218. {
  219. pIpui->dwFlags |= RCUIF_USE_HEADER_COMPRESSION;
  220. }
  221. if (BP_Slip == pEntry->dwBaseProtocol)
  222. {
  223. pIpui->dwFrameSize = pEntry->dwFrameSize;
  224. }
  225. // pmay: 389632
  226. //
  227. // Initialize the dns controls
  228. //
  229. if (pEntry->dwIpDnsFlags & DNS_RegPrimary)
  230. {
  231. if ((pEntry->dwIpDnsFlags & DNS_RegPerConnection) ||
  232. (pEntry->dwIpDnsFlags & DNS_RegDhcpInform))
  233. {
  234. pIpui->dwFlags |= RCUIF_USE_PRIVATE_DNS_SUFFIX;
  235. }
  236. }
  237. else
  238. {
  239. pIpui->dwFlags |= RCUIF_USE_DISABLE_REGISTER_DNS;
  240. }
  241. if (pEntry->pszIpDnsSuffix)
  242. {
  243. lstrcpyn(
  244. pIpui->pszwDnsSuffix,
  245. pEntry->pszIpDnsSuffix,
  246. 255);
  247. }
  248. if (pEntry->dwIpNbtFlags & PBK_ENTRY_IP_NBT_Enable)
  249. {
  250. pIpui->dwFlags |= RCUIF_ENABLE_NBT;
  251. }
  252. return S_OK;
  253. }
  254. EXTERN_C
  255. HRESULT
  256. HrCreateUiInfoCallbackObject (
  257. PEINFO* pInfo,
  258. IUnknown** ppunk)
  259. {
  260. // Validate parameters.
  261. //
  262. if (!pInfo || !ppunk)
  263. {
  264. return E_POINTER;
  265. }
  266. // Create the object and return its IUnknown interface.
  267. // This assumes the object is created with a ref-count of 1.
  268. // (Check the constructor above to make sure.)
  269. //
  270. HRESULT hr = S_OK;
  271. CRasConnectionUiIpInfo* pObj = new CRasConnectionUiIpInfo (pInfo);
  272. if (pObj)
  273. {
  274. *ppunk = static_cast<IUnknown*>(pObj);
  275. }
  276. else
  277. {
  278. *ppunk = NULL;
  279. hr = E_OUTOFMEMORY;
  280. }
  281. return hr;
  282. }
  283. // Set the m_pInfo member to NULL. Since we don't have direct control over
  284. // the lifetime of this object (clients can hold references as long as they
  285. // want) revoking m_pInfo is a saftey net to keep us from trying to access
  286. // memory that may have gone away.
  287. //
  288. EXTERN_C
  289. void
  290. RevokePeinfoFromUiInfoCallbackObject (
  291. IUnknown* punk)
  292. {
  293. CRasConnectionUiIpInfo* pObj = static_cast<CRasConnectionUiIpInfo*>(punk);
  294. pObj->m_pInfo = NULL;
  295. }