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.

609 lines
17 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: R A S U I . C P P
  7. //
  8. // Contents: Implements the base class used to implement the Dialup,
  9. // Direct, Internet, and Vpn connection UI objects.
  10. //
  11. // Notes:
  12. //
  13. // Author: shaunco 17 Dec 1997 (and that's the code complete date!)
  14. //
  15. //----------------------------------------------------------------------------
  16. #include "pch.h"
  17. #pragma hdrstop
  18. #include "netshell.h"
  19. #include "nsbase.h"
  20. #include "nccom.h"
  21. #include "ncras.h"
  22. #include "rasui.h"
  23. #include "rasuip.h"
  24. //+---------------------------------------------------------------------------
  25. //
  26. // Function: HrCreateInboundConfigConnection
  27. //
  28. // Purpose: Create and return the Inbound configuration connection object.
  29. // This is called from inbui.cpp and rasui.cpp.
  30. //
  31. // Arguments:
  32. // ppCon [out] Returned connection object.
  33. //
  34. // Returns: S_OK or an error code
  35. //
  36. // Author: shaunco 25 Feb 1998
  37. //
  38. // Notes: This commonizes this operation which may be performed from
  39. // the direct connect wizard as well as the incoming connections
  40. // wizard.
  41. //
  42. HRESULT
  43. HrCreateInboundConfigConnection (
  44. INetConnection** ppCon)
  45. {
  46. static const CLSID CLSID_InboundConnection =
  47. {0xBA126AD9,0x2166,0x11D1,{0xB1,0xD0,0x00,0x80,0x5F,0xC1,0x27,0x0E}};
  48. Assert (ppCon);
  49. // Initialize the output parameter.
  50. //
  51. *ppCon = NULL;
  52. // Create an uninitialized inbound connection object.
  53. // Ask for the INetInboundConnection interface so we can
  54. // initialize it as the configuration connection.
  55. //
  56. HRESULT hr;
  57. INetInboundConnection* pInbCon;
  58. hr = HrCreateInstance(
  59. CLSID_InboundConnection,
  60. CLSCTX_LOCAL_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  61. &pInbCon);
  62. TraceHr(ttidError, FAL, hr, FALSE, "HrCreateInstance");
  63. if (SUCCEEDED(hr))
  64. {
  65. // Initialize the connection object and return the
  66. // INetConnection interface on it to the caller.
  67. // Pass TRUE so that the remoteaccess service is started.
  68. //
  69. hr = pInbCon->InitializeAsConfigConnection (TRUE);
  70. if (SUCCEEDED(hr))
  71. {
  72. hr = HrQIAndSetProxyBlanket(pInbCon, ppCon);
  73. }
  74. ReleaseObj (pInbCon);
  75. }
  76. TraceHr (ttidError, FAL, hr, FALSE, "HrCreateInboundConfigConnection");
  77. return hr;
  78. }
  79. //+---------------------------------------------------------------------------
  80. //
  81. // Member: CRasUiBase::CRasUiBase
  82. //
  83. // Purpose: Constructor/Destructor
  84. //
  85. // Arguments:
  86. // (none)
  87. //
  88. // Returns:
  89. //
  90. // Author: shaunco 20 Oct 1997
  91. //
  92. // Notes:
  93. //
  94. CRasUiBase::CRasUiBase ()
  95. {
  96. m_pCon = NULL;
  97. m_dwRasWizType = 0;
  98. ZeroMemory (&m_RasConInfo, sizeof(m_RasConInfo));
  99. }
  100. CRasUiBase::~CRasUiBase ()
  101. {
  102. RciFree (&m_RasConInfo);
  103. ReleaseObj (m_pCon);
  104. }
  105. //+---------------------------------------------------------------------------
  106. // INetConnectionUI
  107. //
  108. HRESULT
  109. CRasUiBase::HrSetConnection (
  110. INetConnection* pCon,
  111. CComObjectRootEx <CComObjectThreadModel>* pObj)
  112. {
  113. // Enter our critical section to protect the use of m_pCon.
  114. //
  115. CExceptionSafeComObjectLock EsLock (pObj);
  116. ReleaseObj (m_pCon);
  117. m_pCon = pCon;
  118. AddRefObj (m_pCon);
  119. return S_OK;
  120. }
  121. HRESULT
  122. CRasUiBase::HrConnect (
  123. HWND hwndParent,
  124. DWORD dwFlags,
  125. CComObjectRootEx <CComObjectThreadModel>* pObj,
  126. IUnknown* punk)
  127. {
  128. HRESULT hr = S_OK;
  129. if (!m_pCon)
  130. {
  131. hr = E_UNEXPECTED;
  132. }
  133. else
  134. {
  135. RASCON_INFO RasConInfo;
  136. hr = HrRciGetRasConnectionInfo (m_pCon, &RasConInfo);
  137. if (S_OK == hr)
  138. {
  139. // Dial the entry.
  140. //
  141. RASDIALDLG info;
  142. ZeroMemory (&info, sizeof(info));
  143. info.dwSize = sizeof (RASDIALDLG);
  144. info.hwndOwner = hwndParent;
  145. BOOL fRet = RasDialDlg (
  146. RasConInfo.pszwPbkFile,
  147. RasConInfo.pszwEntryName, NULL, &info);
  148. if (!fRet)
  149. {
  150. // If the fRet was FALSE, but the dwError is zero,
  151. // then the user cancelled. Else it was an error
  152. //
  153. if (0 == info.dwError)
  154. {
  155. hr = S_FALSE;
  156. }
  157. else
  158. {
  159. hr = HRESULT_FROM_WIN32(info.dwError);
  160. }
  161. TraceError ("RasDialDlg", (S_FALSE == hr) ? S_OK : hr);
  162. }
  163. RciFree (&RasConInfo);
  164. }
  165. }
  166. TraceError ("CRasUiBase::HrConnect", (S_FALSE == hr) ? S_OK : hr);
  167. return hr;
  168. }
  169. HRESULT
  170. CRasUiBase::HrDisconnect (
  171. IN HWND hwndParent,
  172. IN DWORD dwFlags)
  173. {
  174. HRESULT hr = S_OK;
  175. if (!m_pCon)
  176. {
  177. hr = E_UNEXPECTED;
  178. }
  179. else
  180. {
  181. // Note that we do not call m_pCon->Disconnect. This is because
  182. // CM has some bad architecture w.r.t. knowing when they have
  183. // disconnected the connection vs. the connection being dropped
  184. // and they need to redial. Thus, for CM's sake, the RasHangup
  185. // call has to take place inside of explorer and not from netman.
  186. // (Tough noogies for clients of INetConnection::Disconnect who
  187. // would like CM connections to be hungup correctly. But, that's
  188. // the nature of a messed up architecture and no one willing to make
  189. // it right -- the hacks start to creep into good code too.)
  190. //
  191. RASCON_INFO RasConInfo;
  192. hr = HrRciGetRasConnectionInfo (m_pCon, &RasConInfo);
  193. if (S_OK == hr)
  194. {
  195. HRASCONN hRasConn;
  196. hr = HrFindRasConnFromGuidId (&RasConInfo.guidId, &hRasConn, NULL);
  197. if (S_OK == hr)
  198. {
  199. hr = HrRasHangupUntilDisconnected (hRasConn);
  200. }
  201. else if (S_FALSE == hr)
  202. {
  203. // Not connected.
  204. //
  205. hr = S_OK;
  206. }
  207. RciFree (&RasConInfo);
  208. }
  209. }
  210. TraceHr (ttidError, FAL, hr, FALSE, "CRasUiBase::HrDisconnect");
  211. return hr;
  212. }
  213. //+---------------------------------------------------------------------------
  214. // INetConnectionPropertyUi2
  215. //
  216. HRESULT
  217. CRasUiBase::HrAddPropertyPages (
  218. HWND hwndParent,
  219. LPFNADDPROPSHEETPAGE pfnAddPage,
  220. LPARAM lParam)
  221. {
  222. HRESULT hr = S_OK;
  223. // Validate parameters.
  224. //
  225. if ((hwndParent && !IsWindow (hwndParent)) ||
  226. !pfnAddPage)
  227. {
  228. hr = E_POINTER;
  229. }
  230. // Must have called SetConnection prior to this.
  231. //
  232. else if (!m_pCon)
  233. {
  234. hr = E_UNEXPECTED;
  235. }
  236. else
  237. {
  238. RciFree (&m_RasConInfo);
  239. hr = HrRciGetRasConnectionInfo (m_pCon, &m_RasConInfo);
  240. if (S_OK == hr)
  241. {
  242. ZeroMemory (&m_RasEntryDlg, sizeof(m_RasEntryDlg));
  243. m_RasEntryDlg.dwSize = sizeof(m_RasEntryDlg);
  244. m_RasEntryDlg.hwndOwner = hwndParent;
  245. m_RasEntryDlg.dwFlags = RASEDFLAG_ShellOwned;
  246. m_RasEntryDlg.reserved2 = reinterpret_cast<ULONG_PTR>
  247. (&m_ShellCtx);
  248. ZeroMemory (&m_ShellCtx, sizeof(m_ShellCtx));
  249. m_ShellCtx.pfnAddPage = pfnAddPage;
  250. m_ShellCtx.lparam = lParam;
  251. BOOL fRet = RasEntryDlgW (
  252. m_RasConInfo.pszwPbkFile,
  253. m_RasConInfo.pszwEntryName,
  254. &m_RasEntryDlg);
  255. if (!fRet)
  256. {
  257. TraceError ("CRasUiBase::AddPropertyPages: RasEntryDlg "
  258. "returned an error",
  259. HRESULT_FROM_WIN32 (m_RasEntryDlg.dwError));
  260. }
  261. }
  262. hr = S_OK;
  263. }
  264. TraceError ("CRasUiBase::HrAddPropertyPages", hr);
  265. return hr;
  266. }
  267. //+---------------------------------------------------------------------------
  268. // INetConnectionWizardUi
  269. //
  270. HRESULT
  271. CRasUiBase::HrQueryMaxPageCount (
  272. INetConnectionWizardUiContext* pContext,
  273. DWORD* pcMaxPages)
  274. {
  275. HRESULT hr;
  276. // Validate parameters.
  277. //
  278. if (!pcMaxPages)
  279. {
  280. hr = E_POINTER;
  281. }
  282. else
  283. {
  284. *pcMaxPages = RasWizQueryMaxPageCount (m_dwRasWizType);
  285. hr = S_OK;
  286. }
  287. TraceError ("CRasUiBase::HrQueryMaxPageCount", hr);
  288. return hr;
  289. }
  290. BOOL bCallRasDlgEntry = TRUE;
  291. HRESULT
  292. CRasUiBase::HrAddWizardPages (
  293. INetConnectionWizardUiContext* pContext,
  294. LPFNADDPROPSHEETPAGE pfnAddPage,
  295. LPARAM lParam,
  296. DWORD dwFlags)
  297. {
  298. HRESULT hr = S_OK;
  299. if (!bCallRasDlgEntry)
  300. {
  301. return E_ABORT;
  302. }
  303. // Validate parameters.
  304. //
  305. if (!pfnAddPage)
  306. {
  307. hr = E_POINTER;
  308. }
  309. else
  310. {
  311. ZeroMemory (&m_ShellCtx, sizeof(m_ShellCtx));
  312. m_ShellCtx.pfnAddPage = pfnAddPage;
  313. m_ShellCtx.lparam = lParam;
  314. ZeroMemory (&m_RasEntryDlg, sizeof(m_RasEntryDlg));
  315. m_RasEntryDlg.dwSize = sizeof(m_RasEntryDlg);
  316. m_RasEntryDlg.dwFlags = dwFlags | RASEDFLAG_ShellOwned;
  317. m_RasEntryDlg.reserved2 = reinterpret_cast<ULONG_PTR>(&m_ShellCtx);
  318. BOOL fRet = RasEntryDlgW (NULL, NULL, &m_RasEntryDlg);
  319. if (fRet)
  320. {
  321. Assert (m_ShellCtx.pvWizardCtx);
  322. }
  323. else
  324. {
  325. TraceError ("CRasUiBase::HrAddWizardPages: RasEntryDlg "
  326. "returned an error",
  327. HRESULT_FROM_WIN32 (m_RasEntryDlg.dwError));
  328. if (0 == m_RasEntryDlg.dwError)
  329. {
  330. bCallRasDlgEntry = FALSE;
  331. // Don't call this again if user cancelled out of TAPI phone dialog box.
  332. }
  333. // RAS may not be installed or may otherwise have a problem.
  334. // We can safely ignore any errors.
  335. }
  336. }
  337. TraceError ("CRasUiBase::HrAddWizardPages", hr);
  338. return hr;
  339. }
  340. HRESULT
  341. CRasUiBase::HrGetSuggestedConnectionName (
  342. PWSTR* ppszwSuggestedName)
  343. {
  344. HRESULT hr;
  345. // Validate parameters.
  346. //
  347. if (!ppszwSuggestedName)
  348. {
  349. hr = E_POINTER;
  350. }
  351. else
  352. {
  353. Assert (m_ShellCtx.pvWizardCtx);
  354. WCHAR pszwSuggestedName [MAX_PATH];
  355. DWORD dwErr = RasWizGetUserInputConnectionName (
  356. m_ShellCtx.pvWizardCtx,
  357. pszwSuggestedName);
  358. hr = HRESULT_FROM_WIN32 (dwErr);
  359. TraceError ("RasWizGetUserInputConnectionName", hr);
  360. if (SUCCEEDED(hr))
  361. {
  362. hr = HrCoTaskMemAllocAndDupSz (
  363. pszwSuggestedName,
  364. ppszwSuggestedName,
  365. NETCON_MAX_NAME_LEN);
  366. }
  367. }
  368. TraceError ("CRasUiBase::HrGetSuggestedConnectionName", hr);
  369. return hr;
  370. }
  371. HRESULT
  372. CRasUiBase::HrSetConnectionName (
  373. PCWSTR pszwConnectionName)
  374. {
  375. HRESULT hr;
  376. // Validate parameters.
  377. //
  378. if (!pszwConnectionName)
  379. {
  380. hr = E_POINTER;
  381. }
  382. else
  383. {
  384. Assert (m_ShellCtx.pvWizardCtx);
  385. m_strConnectionName = pszwConnectionName;
  386. DWORD dwErr = RasWizSetEntryName (m_dwRasWizType,
  387. m_ShellCtx.pvWizardCtx,
  388. pszwConnectionName);
  389. hr = HRESULT_FROM_WIN32 (dwErr);
  390. TraceError ("RasWizSetEntryName", hr);
  391. }
  392. TraceError ("CRasUiBase::HrSetConnectionName", hr);
  393. return hr;
  394. }
  395. HRESULT
  396. CRasUiBase::HrGetNewConnection (
  397. INetConnection** ppCon)
  398. {
  399. static const CLSID CLSID_DialupConnection =
  400. {0xBA126AD7,0x2166,0x11D1,{0xB1,0xD0,0x00,0x80,0x5F,0xC1,0x27,0x0E}};
  401. HRESULT hr;
  402. // Validate parameters.
  403. //
  404. if (!ppCon)
  405. {
  406. hr = E_POINTER;
  407. }
  408. // Must have called SetConnectionName prior to this.
  409. //
  410. else if (m_strConnectionName.empty())
  411. {
  412. hr = E_UNEXPECTED;
  413. }
  414. else
  415. {
  416. Assert (m_ShellCtx.pvWizardCtx);
  417. // Call into rasdlg to finish creating the entry and to return
  418. // us the phonebook and entry name. We'll use them to create
  419. // the connection object.
  420. //
  421. WCHAR pszwPbkFile [MAX_PATH];
  422. WCHAR pszwEntryName [MAX_PATH];
  423. DWORD dwFlags;
  424. DWORD dwErr = RasWizCreateNewEntry (m_dwRasWizType,
  425. m_ShellCtx.pvWizardCtx,
  426. pszwPbkFile, pszwEntryName, &dwFlags);
  427. hr = HRESULT_FROM_WIN32 (dwErr);
  428. TraceError ("RasWizCreateNewEntry", hr);
  429. if (SUCCEEDED(hr))
  430. {
  431. // Create the inbound configuration connection if requested.
  432. // This will happen when the direct connect wizard is invoked
  433. // and the user chooses to be the host.
  434. //
  435. if (dwFlags & NCC_FLAG_CREATE_INCOMING)
  436. {
  437. hr = HrCreateInboundConfigConnection (ppCon);
  438. }
  439. else
  440. {
  441. // Create an uninitialized dialup connection object.
  442. // Ask for the INetRasConnection interface so we can
  443. // initialize it.
  444. //
  445. INetRasConnection* pRasCon;
  446. hr = HrCreateInstance(
  447. CLSID_DialupConnection,
  448. CLSCTX_LOCAL_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  449. &pRasCon);
  450. TraceHr(ttidError, FAL, hr, FALSE, "HrCreateInstance");
  451. if (SUCCEEDED(hr))
  452. {
  453. NcSetProxyBlanket (pRasCon);
  454. // Initialize the connection object and return the
  455. // INetConnection interface on it to the caller.
  456. //
  457. RASCON_INFO RasConInfo;
  458. ZeroMemory (&RasConInfo, sizeof(RasConInfo));
  459. RasConInfo.pszwPbkFile = pszwPbkFile;
  460. RasConInfo.pszwEntryName = pszwEntryName;
  461. hr = pRasCon->SetRasConnectionInfo (&RasConInfo);
  462. if (SUCCEEDED(hr))
  463. {
  464. hr = HrQIAndSetProxyBlanket(pRasCon, ppCon);
  465. if (S_OK == hr)
  466. {
  467. NcSetProxyBlanket (*ppCon);
  468. }
  469. }
  470. ReleaseObj (pRasCon);
  471. }
  472. }
  473. }
  474. }
  475. TraceError ("CRasUiBase::HrGetNewConnection", hr);
  476. return hr;
  477. }
  478. HRESULT
  479. CRasUiBase::HrGetNewConnectionInfo (
  480. OUT DWORD* pdwFlags)
  481. {
  482. HRESULT hr;
  483. // Validate parameters.
  484. //
  485. if (!pdwFlags)
  486. {
  487. hr = E_POINTER;
  488. }
  489. else
  490. {
  491. *pdwFlags = 0;
  492. Assert (m_ShellCtx.pvWizardCtx);
  493. DWORD dwRasFlags;
  494. DWORD dwErr = RasWizGetNCCFlags (
  495. m_dwRasWizType, m_ShellCtx.pvWizardCtx,
  496. &dwRasFlags);
  497. hr = HRESULT_FROM_WIN32 (dwErr);
  498. TraceError ("RasWizGetNCCFlags", hr);
  499. if (SUCCEEDED(hr))
  500. {
  501. if (dwRasFlags & NCC_FLAG_CREATE_INCOMING)
  502. {
  503. *pdwFlags |= NCWF_INCOMINGCONNECTION;
  504. }
  505. if (dwRasFlags & NCC_FLAG_FIREWALL)
  506. {
  507. *pdwFlags |= NCWF_FIREWALLED;
  508. }
  509. if (dwRasFlags & NCC_FLAG_SHARED)
  510. {
  511. *pdwFlags |= NCWF_SHARED;
  512. }
  513. if (dwRasFlags & NCC_FLAG_ALL_USERS)
  514. {
  515. *pdwFlags |= NCWF_ALLUSER_CONNECTION;
  516. }
  517. if (dwRasFlags & NCC_FLAG_GLOBALCREDS)
  518. {
  519. *pdwFlags |= NCWF_GLOBAL_CREDENTIALS;
  520. }
  521. if (dwRasFlags & NCC_FLAG_DEFAULT_INTERNET)
  522. {
  523. *pdwFlags |= NCWF_DEFAULT;
  524. }
  525. }
  526. else if (E_INVALIDARG == hr)
  527. {
  528. hr = E_UNEXPECTED;
  529. }
  530. }
  531. TraceError ("CRasUiBase::HrGetNewConnectionInfo", hr);
  532. return hr;
  533. }