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.

991 lines
28 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: L A N U I O B J. C P P
  7. //
  8. // Contents: Implementation of the LAN ConnectionUI object
  9. //
  10. // Notes:
  11. //
  12. // Created: tongl 8 Oct 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "lancmn.h"
  18. #include "lanui.h"
  19. #include "wzcui.h"
  20. #include "lanuiobj.h"
  21. #include "lanwiz.h"
  22. #include "ncnetcon.h"
  23. #include "ncras.h"
  24. #include "lanhelp.h"
  25. #include "ncperms.h"
  26. #include "advpage.h"
  27. #include "cfpidl.h"
  28. #include "..\folder\confold.h"
  29. #include "..\folder\connlist.h"
  30. #include "ncsvc.h"
  31. extern const WCHAR c_szBiNdisAtm[];
  32. extern const WCHAR c_szInfId_MS_AtmElan[];
  33. const WCHAR c_szTcpip[] = L"Tcpip";
  34. //+---------------------------------------------------------------------------
  35. // INetConnectionUI
  36. //
  37. //+---------------------------------------------------------------------------
  38. //
  39. // Member: CLanConnectionUi::SetConnection
  40. //
  41. // Purpose: Sets the LAN connection that this UI object will operate upon
  42. //
  43. // Arguments:
  44. // pCon [in] LAN connection object to operate on. Can be NULL.
  45. //
  46. // Returns: S_OK if success, OLE error otherwise
  47. //
  48. // Author: danielwe 16 Oct 1997
  49. //
  50. // Notes:
  51. //
  52. STDMETHODIMP CLanConnectionUi::SetConnection(INetConnection* pCon)
  53. {
  54. HRESULT hr = S_OK;
  55. ReleaseObj(m_pconn);
  56. m_pconn = pCon;
  57. AddRefObj(m_pconn);
  58. TraceError("CLanConnectionUi::SetConnection", hr);
  59. return hr;
  60. }
  61. //+---------------------------------------------------------------------------
  62. //
  63. // Member: CLanConnectionUi::Connect
  64. //
  65. // Purpose: Tells the connection to connect, optionally displaying UI of
  66. // connection progress.
  67. //
  68. // Arguments:
  69. // hwndParent [in] Parent window for UI
  70. // dwFlags [in] Flags affecting how UI is shown
  71. //
  72. // Returns: S_OK if success, OLE error otherwise
  73. //
  74. // Author: danielwe 16 Oct 1997
  75. //
  76. // Notes:
  77. //
  78. STDMETHODIMP CLanConnectionUi::Connect(HWND hwndParent, DWORD dwFlags)
  79. {
  80. HRESULT hr = S_OK;
  81. if (!m_pconn)
  82. {
  83. hr = E_UNEXPECTED;
  84. }
  85. else
  86. {
  87. CLanConnectionUiDlg dlg;
  88. HWND hwndDlg;
  89. if (!(dwFlags & NCUC_NO_UI))
  90. {
  91. // Display UI prior to connect
  92. //
  93. dlg.SetConnection(m_pconn);
  94. hwndDlg = dlg.Create(hwndParent);
  95. if (!hwndDlg)
  96. {
  97. hr = E_FAIL;
  98. }
  99. }
  100. if (SUCCEEDED(hr))
  101. {
  102. hr = m_pconn->Connect();
  103. // Sleep a bit so they can read the text
  104. Sleep(1000);
  105. if (!(dwFlags & NCUC_NO_UI))
  106. {
  107. SetDlgItemText(hwndDlg, IDC_TXT_Caption, c_szEmpty);
  108. Sleep(100);
  109. UINT ids = SUCCEEDED(hr) ?
  110. IDS_LAN_CONNECTED :
  111. IDS_LAN_CONNECT_FAILED;
  112. PCWSTR szwResult = SzLoadIds(ids);
  113. SetDlgItemText(hwndDlg, IDC_TXT_Caption, szwResult);
  114. // Sleep a bit so they can read the text
  115. Sleep(1000);
  116. DestroyWindow(hwndDlg);
  117. }
  118. }
  119. }
  120. TraceHr(ttidError, FAL, hr, FALSE, "CLanConnectionUi::Connect");
  121. return hr;
  122. }
  123. STDMETHODIMP CLanConnectionUi::Disconnect(HWND hwndParent, DWORD dwFlags)
  124. {
  125. HRESULT hr = S_OK;
  126. if (!m_pconn)
  127. {
  128. hr = E_UNEXPECTED;
  129. }
  130. else
  131. {
  132. hr = m_pconn->Disconnect();
  133. }
  134. TraceHr (ttidError, FAL, hr, FALSE, "CLanConnectionUi::Disconnect");
  135. return hr;
  136. }
  137. //+---------------------------------------------------------------------------
  138. // INetConnectionPropertyUi
  139. //
  140. //+---------------------------------------------------------------------------
  141. //
  142. // Member: CLanConnectionUi::AddPages
  143. //
  144. // Purpose: Called when our UI object shoud add its pages to a property
  145. // sheet for the connection UI owned by the shell.
  146. //
  147. // Arguments:
  148. // pfnAddPage [in] Callback function to add the page
  149. // lParam [in] User-defined paramter required by the callback
  150. // function.
  151. //
  152. // Returns: S_OK if succeeded, otherwise OLE error.
  153. //
  154. // Author: danielwe 28 Oct 1997
  155. //
  156. // Notes:
  157. //
  158. STDMETHODIMP CLanConnectionUi::AddPages(HWND hwndParent,
  159. LPFNADDPROPSHEETPAGE pfnAddPage,
  160. LPARAM lParam)
  161. {
  162. HRESULT hr = S_OK;
  163. if (!pfnAddPage)
  164. {
  165. hr = E_POINTER;
  166. }
  167. else if (!m_pconn)
  168. {
  169. hr = E_UNEXPECTED;
  170. }
  171. else
  172. {
  173. NETCON_PROPERTIES* pProperties;
  174. hr = m_pconn->GetProperties(&pProperties);
  175. if(SUCCEEDED(hr))
  176. {
  177. BOOL bShift = (0x8000 & GetKeyState(VK_SHIFT)); // ISSUE-2000/08/28-kenwic For debugging bridge bindings, remove before ship
  178. if(!bShift && pProperties->MediaType == NCM_BRIDGE)
  179. {
  180. if (!m_pspNet)
  181. {
  182. m_pspNet = new CLanNetNetworkBridgePage(static_cast<INetConnectionPropertyUi *>(this),
  183. m_pnc, m_pconn, m_fReadOnly, m_fNeedReboot,
  184. m_fAccessDenied, g_aHelpIDs_IDD_LAN_NETWORKING);
  185. }
  186. if (m_pspNet)
  187. {
  188. (VOID) pfnAddPage(m_pspNet->CreatePage(IDD_LAN_NETWORKING_MACBRIDGE, 0),
  189. lParam);
  190. }
  191. }
  192. else if(!bShift && pProperties->dwCharacter & NCCF_BRIDGED)
  193. {
  194. if (!m_pspNet)
  195. {
  196. m_pspNet = new CLanNetBridgedPage(static_cast<INetConnectionPropertyUi *>(this),
  197. m_pnc, m_pconn, m_fReadOnly, m_fNeedReboot,
  198. m_fAccessDenied, g_aHelpIDs_IDD_LAN_NETWORKING);
  199. }
  200. if (m_pspNet)
  201. {
  202. (VOID) pfnAddPage(m_pspNet->CreatePage(IDD_LAN_NETWORKING_BRIDGED, 0),
  203. lParam);
  204. }
  205. }
  206. else
  207. {
  208. if (!m_pspNet)
  209. {
  210. m_pspNet = new CLanNetNormalPage(static_cast<INetConnectionPropertyUi *>(this),
  211. m_pnc, m_pconn, m_fReadOnly, m_fNeedReboot,
  212. m_fAccessDenied, g_aHelpIDs_IDD_LAN_NETWORKING);
  213. }
  214. if (m_pspNet)
  215. {
  216. (VOID) pfnAddPage(m_pspNet->CreatePage(IDD_LAN_NETWORKING, 0),
  217. lParam);
  218. }
  219. }
  220. FreeNetconProperties(pProperties);
  221. }
  222. // display the "Wireless Zero Configuration" page
  223. //
  224. // for now (WinXP Client RTM) the decision was made to let everybody party, but based on
  225. // the acl below. Later, the security schema won't change by default, but support will be
  226. // added allowing admins to tighten up the access to the service RPC APIs.
  227. if (m_pspWZeroConf==NULL /*&& FIsUserAdmin()*/)
  228. {
  229. m_pspWZeroConf = new CWZeroConfPage(static_cast<INetConnectionPropertyUi *>(this),
  230. m_pnc, m_pconn , g_aHelpIDs_IDD_LAN_WZEROCONF);
  231. // The page should show up only if the adapter is wireless and if
  232. // the wzcsvc service is responding to calls.
  233. if (!m_pspWZeroConf->IsWireless())
  234. {
  235. delete m_pspWZeroConf;
  236. m_pspWZeroConf = NULL;
  237. }
  238. }
  239. if (m_pspWZeroConf != NULL)
  240. {
  241. (VOID) pfnAddPage(
  242. m_pspWZeroConf->CreatePage(
  243. IDD_LAN_WZEROCONF,
  244. 0),
  245. lParam);
  246. }
  247. //
  248. // display the "Security" page
  249. if (m_pspWZeroConf == NULL && !m_pspSecurity)
  250. {
  251. TraceTag (ttidLanUi, "OnInitDialog: Calling ElCanEapolRunOnInterface");
  252. if (ElCanEapolRunOnInterface (m_pconn))
  253. {
  254. TraceTag (ttidLanUi, "OnInitDialog: Can surely display Authentication tab on interface");
  255. m_pspSecurity = new CLanSecurityPage(static_cast<INetConnectionPropertyUi *>(this),
  256. m_pnc, m_pconn,
  257. g_aHelpIDs_IDD_SECURITY);
  258. }
  259. else
  260. {
  261. TraceTag (ttidLanUi, "OnInitDialog: Cannot display Authentication tab on interface");
  262. }
  263. }
  264. if (m_pspSecurity)
  265. {
  266. (VOID) pfnAddPage(
  267. m_pspSecurity->CreatePage(
  268. IDD_LAN_SECURITY,
  269. 0,
  270. NULL,
  271. NULL,
  272. NULL,
  273. WZCGetSPResModule()),
  274. lParam);
  275. }
  276. // Check to see what homenet pages should be shown. These pages are
  277. // never shown if the user is not an admin, as such a user will not
  278. // have rights to modify the WMI store, which may be necessary just
  279. // to retrieve the IHNetConnection
  280. //
  281. // (a) The page is not displayed unless the user is an admin
  282. // or power-user, and the user has rights to share connections.
  283. //
  284. if (IsHNetAllowed(NCPERM_ShowSharedAccessUi) || IsHNetAllowed(NCPERM_PersonalFirewallConfig))
  285. {
  286. // (b) The page is not displayed unless TCP/IP is installed.
  287. //
  288. DWORD dwState;
  289. if (SUCCEEDED(HrSvcQueryStatus(c_szTcpip, &dwState)) && dwState == SERVICE_RUNNING)
  290. {
  291. IHNetCfgMgr *pHNetCfgMgr;
  292. IHNetIcsSettings *pHNetIcsSettings;
  293. IHNetConnection *pHNConn;
  294. hr = CoCreateInstance(
  295. CLSID_HNetCfgMgr,
  296. NULL,
  297. CLSCTX_ALL,
  298. IID_IHNetCfgMgr,
  299. reinterpret_cast<void**>(&pHNetCfgMgr)
  300. );
  301. if (SUCCEEDED(hr))
  302. {
  303. hr = pHNetCfgMgr->QueryInterface(
  304. __uuidof(pHNetIcsSettings),
  305. reinterpret_cast<void**>(&pHNetIcsSettings)
  306. );
  307. if (SUCCEEDED(hr))
  308. {
  309. hr = pHNetCfgMgr->GetIHNetConnectionForINetConnection(
  310. m_pconn,
  311. &pHNConn
  312. );
  313. if (SUCCEEDED(hr))
  314. {
  315. // display the 'Advanced' page if necessary
  316. //
  317. if (!m_pspAdvanced)
  318. {
  319. hr = HrQueryLanAdvancedPage(
  320. m_pconn,
  321. static_cast<INetConnectionPropertyUi *>(this),
  322. m_pspAdvanced,
  323. pHNetCfgMgr,
  324. pHNetIcsSettings,
  325. pHNConn);
  326. }
  327. if (m_pspAdvanced)
  328. {
  329. (VOID) pfnAddPage(
  330. m_pspAdvanced->CreatePage(IDD_LAN_ADVANCED, 0),
  331. lParam);
  332. }
  333. ReleaseObj(pHNConn);
  334. }
  335. ReleaseObj(pHNetIcsSettings);
  336. }
  337. ReleaseObj(pHNetCfgMgr);
  338. }
  339. if(FAILED(hr))
  340. {
  341. if(!m_pspHomenetUnavailable)
  342. {
  343. hr = HrCreateHomenetUnavailablePage(hr, m_pspHomenetUnavailable);
  344. }
  345. if (m_pspHomenetUnavailable)
  346. {
  347. (VOID) pfnAddPage(
  348. m_pspHomenetUnavailable->CreatePage(IDD_LAN_HOMENETUNAVAILABLE, 0),
  349. lParam);
  350. }
  351. hr = S_OK;
  352. }
  353. }
  354. }
  355. }
  356. TraceError("CLanConnectionUi::AddPages(INetConnectionPropertyUi)", hr);
  357. return hr;
  358. }
  359. //+---------------------------------------------------------------------------
  360. // INetConnectionPropertyUi2
  361. //
  362. STDMETHODIMP
  363. CLanConnectionUi::GetIcon (
  364. DWORD dwSize,
  365. HICON *phIcon )
  366. {
  367. HRESULT hr;
  368. Assert (phIcon);
  369. hr = HrGetIconFromMediaType(dwSize, NCM_LAN, NCSM_LAN, 7, 0, phIcon);
  370. TraceError ("CLanConnectionUi::GetIcon (INetConnectionPropertyUi2)", hr);
  371. return hr;
  372. }
  373. //+---------------------------------------------------------------------------
  374. // INetConnectionWizardUi Methods
  375. //
  376. //+---------------------------------------------------------------------------
  377. //
  378. // Member: CLanConnectionUi::QueryMaxPageCount
  379. //
  380. // Purpose:
  381. //
  382. // Arguments:
  383. // pContext [in]
  384. // pcMaxPages [out]
  385. //
  386. // Returns: HRESULT, Error code.
  387. //
  388. // Author: tongl 9 Oct 1997
  389. //
  390. // Notes:
  391. //
  392. STDMETHODIMP CLanConnectionUi::QueryMaxPageCount(INetConnectionWizardUiContext* pContext,
  393. DWORD* pcMaxPages)
  394. {
  395. // Keep the pContext if we have not got one before
  396. // for later use (to get the writable INetCfg *, for instance)
  397. Assert(pContext);
  398. Assert(pcMaxPages);
  399. if (!m_pContext)
  400. {
  401. m_pContext = pContext;
  402. AddRefObj(pContext);
  403. }
  404. *pcMaxPages = 1;
  405. return S_OK;
  406. }
  407. //+---------------------------------------------------------------------------
  408. //
  409. // Member: CLanConnectionUi::AddPages
  410. //
  411. // Purpose:
  412. //
  413. // Arguments:
  414. // INetConnectionWizardUiContext* pContext [in]
  415. // LPFNADDPROPSHEETPAGE pfnAddPage [in]
  416. // LPARAM lParam [in]
  417. //
  418. // Returns: HRESULT, Error code.
  419. //
  420. // Author: tongl 9 Oct 1997
  421. //
  422. // Notes:
  423. //
  424. STDMETHODIMP CLanConnectionUi::AddPages(INetConnectionWizardUiContext* pContext,
  425. LPFNADDPROPSHEETPAGE lpfnAddPage,
  426. LPARAM lParam)
  427. {
  428. // 1) Keep the pContext if we have not got one before
  429. // for later use (to get the writable INetCfg *, for instance)
  430. Assert(pContext);
  431. if (!m_pContext)
  432. {
  433. m_pContext = pContext;
  434. AddRefObj(pContext);
  435. }
  436. HPROPSHEETPAGE * ahpsp = NULL;
  437. INT cPages = 0;
  438. // 2) Call "lpfnAddPage(hpsp, lParam)" for every
  439. // wizard page in the right order
  440. // Get all wizard pages
  441. // $REVIEW(tongl 10/30/97): With current design,
  442. // LAN wizard has one page only
  443. HRESULT hr = HrSetupWizPages(pContext, &ahpsp, &cPages);
  444. if (SUCCEEDED(hr))
  445. {
  446. HPROPSHEETPAGE hpspCurrentPage = NULL;
  447. while (cPages--)
  448. {
  449. hpspCurrentPage = *ahpsp;
  450. ahpsp++;
  451. // Add each wizard page
  452. if (lpfnAddPage(hpspCurrentPage, lParam))
  453. {
  454. // We successfully made the hand off to the requestor
  455. // Now we reset our handle so we don't try to free it
  456. hpspCurrentPage = NULL;
  457. }
  458. // clean up if needed
  459. if (hpspCurrentPage)
  460. {
  461. TraceError("CLanConnectionUi::AddPages, Failed to add one wizard page...", E_FAIL);
  462. DestroyPropertySheetPage(hpspCurrentPage);
  463. }
  464. }
  465. }
  466. TraceError("CLanConnectionUi::AddPages", hr);
  467. return hr;
  468. }
  469. //+---------------------------------------------------------------------------
  470. //
  471. // Member: CLanConnectionUi::GetSuggestedConnectionName
  472. //
  473. // Purpose:
  474. //
  475. // Arguments:
  476. // BSTR * bstrSuggestedName [out]
  477. //
  478. // Returns: HRESULT, Error code.
  479. //
  480. // Author: tongl 9 Dec 1997
  481. //
  482. // Notes:
  483. //
  484. STDMETHODIMP CLanConnectionUi::GetSuggestedConnectionName(
  485. PWSTR* ppszwSuggestedName)
  486. {
  487. HRESULT hr = S_OK;
  488. // Validate parameters.
  489. //
  490. if (!ppszwSuggestedName)
  491. {
  492. hr = E_POINTER;
  493. }
  494. else
  495. {
  496. GUID guid;
  497. hr = m_pnccAdapter->GetInstanceGuid(&guid);
  498. if (SUCCEEDED(hr))
  499. {
  500. LPWSTR szName;
  501. CIntelliName Intelliname(_Module.GetResourceInstance(), NULL);
  502. Intelliname.GenerateName(guid, NCM_LAN, 0, NULL, &szName);
  503. hr = HrCoTaskMemAllocAndDupSz ( szName, ppszwSuggestedName);
  504. LocalFree(szName);
  505. }
  506. }
  507. TraceError("CLanConnectionUi::GetSuggestedConnectionName", hr);
  508. return hr;
  509. }
  510. //+---------------------------------------------------------------------------
  511. //
  512. // Member: CLanConnectionUi::GetNewConnectionInfo
  513. //
  514. // Purpose: Allow provider control over renaming the current connection
  515. // and the optional creation of connection shortcuts
  516. //
  517. // Arguments:
  518. //
  519. // Returns: HRESULT, Error code.
  520. //
  521. // Author: scottbri 02 Feb 1998
  522. //
  523. // Notes:
  524. //
  525. STDMETHODIMP CLanConnectionUi::GetNewConnectionInfo(
  526. DWORD* pdwFlags,
  527. NETCON_MEDIATYPE* pMediaType)
  528. {
  529. *pdwFlags = 0;
  530. *pMediaType = NCM_LAN;
  531. return S_OK;
  532. }
  533. //+---------------------------------------------------------------------------
  534. //
  535. // Member: CLanConnectionUi::SetConnectionName
  536. //
  537. // Purpose:
  538. //
  539. // Arguments:
  540. // PCWSTR pszwConnectionName [in]
  541. //
  542. // Returns: HRESULT, Error code.
  543. //
  544. // Author: tongl 9 Oct 1997
  545. //
  546. // Notes:
  547. //
  548. STDMETHODIMP CLanConnectionUi::SetConnectionName(PCWSTR pszwConnectionName)
  549. {
  550. HRESULT hr = S_OK;
  551. // 1) If the pointer is NULL or string is empty, return E_INVALIDAR
  552. if ((!pszwConnectionName) || !wcslen(pszwConnectionName))
  553. {
  554. hr = E_INVALIDARG;
  555. }
  556. else
  557. {
  558. // 2) Otherwise, save the name to m_strConnectionName
  559. // $REVIEW(tongl 12\23\97): Scott expects this function to return
  560. // HRESULT_FROM_WIN32(ERROR_DUP_NAME)
  561. // Here is what we are supposed to do:
  562. // 1) Call HrIsConnectionNameUnique to determine if the name is unique
  563. // 2) Call m_pLanConn->SetInfo if we have a valid connection already
  564. // i.e. GetNewConnection has been called.
  565. AssertSz(m_pnccAdapter, "How come we dont have the device yet ?");
  566. if (m_pnccAdapter)
  567. {
  568. GUID guidConn;
  569. hr = m_pnccAdapter->GetInstanceGuid(&guidConn);
  570. if (SUCCEEDED(hr))
  571. {
  572. hr = HrIsConnectionNameUnique(guidConn,
  573. pszwConnectionName);
  574. if (S_FALSE == hr) // is duplicate
  575. {
  576. hr = HRESULT_FROM_WIN32(ERROR_DUP_NAME);
  577. }
  578. else if (S_OK == hr)
  579. {
  580. m_strConnectionName = pszwConnectionName;
  581. if (m_pLanConn)
  582. {
  583. LANCON_INFO lci = {0};
  584. lci.szwConnName = const_cast<PWSTR>(pszwConnectionName);
  585. m_pLanConn->SetInfo(LCIF_NAME, &lci);
  586. }
  587. }
  588. }
  589. }
  590. }
  591. TraceErrorOptional("CLanConnectionUi::SetConnectionName", hr,
  592. HRESULT_FROM_WIN32(ERROR_DUP_NAME) == hr);
  593. return hr;
  594. }
  595. //+---------------------------------------------------------------------------
  596. //
  597. // Member: CLanConnectionUi::GetNewConnection
  598. //
  599. // Purpose:
  600. //
  601. // Arguments:
  602. // INetConnection** ppCon [out]
  603. //
  604. // Returns: HRESULT, Error code.
  605. //
  606. // Author: tongl 9 Oct 1997
  607. //
  608. // Notes:
  609. //
  610. STDMETHODIMP CLanConnectionUi::GetNewConnection(INetConnection** ppCon)
  611. {
  612. Assert (ppCon);
  613. *ppCon = NULL;
  614. // Enumerate existing connections and get the INetLanConnection *
  615. // as follows:
  616. // 1) If connection for the current m_pnccAdapter exists
  617. // simply use the existing INetLanConnection *
  618. // 2) If connection for the current m_pnccAdapter does not exist
  619. // CreateInstance to get a new INetLanConnection *
  620. INetLanConnection * pLanConn = NULL;
  621. HRESULT hr = HrGetLanConnection(&pLanConn);
  622. if (SUCCEEDED(hr))
  623. {
  624. // Call INetLanConnection::SetInfo if m_strConnName is not empty
  625. Assert(pLanConn);
  626. ReleaseObj(m_pLanConn);
  627. m_pLanConn = pLanConn;
  628. if (!m_strConnectionName.empty())
  629. {
  630. LANCON_INFO lci = {0};
  631. lci.szwConnName = const_cast<PWSTR>(m_strConnectionName.c_str());
  632. pLanConn->SetInfo(LCIF_NAME, &lci);
  633. }
  634. // Return the INetConnection pointer
  635. hr = HrQIAndSetProxyBlanket(pLanConn, &ppCon);
  636. }
  637. TraceError("CLanConnectionUi::GetNewConnection", hr);
  638. return hr;
  639. }
  640. //+---------------------------------------------------------------------------
  641. // INetLanConnectionWizardUi Methods
  642. //+---------------------------------------------------------------------------
  643. //
  644. // Member: CLanConnectionUi::SetDeviceComponent
  645. //
  646. // Purpose:
  647. //
  648. // Arguments:
  649. // GUID pguid [in]
  650. //
  651. // Returns: HRESULT, Error code.
  652. // S_OK if the GUID matches a installed net device's GUID.
  653. // E_FAIL if no match found.
  654. //
  655. // Author: tongl 19 Oct 1997
  656. //
  657. // Notes:
  658. //
  659. STDMETHODIMP CLanConnectionUi::SetDeviceComponent(const GUID * pguid)
  660. {
  661. HRESULT hr = S_OK;
  662. // AddPages must be called before SetDeviceComponent is called
  663. AssertSz(m_pContext, "We do not have a valid context yet ?!");
  664. if (!m_pnc)
  665. {
  666. hr = m_pContext->GetINetCfg(&m_pnc);
  667. }
  668. // Reset the adapter
  669. ReleaseObj(m_pnccAdapter);
  670. m_pnccAdapter = NULL;
  671. // Reset the connection
  672. ReleaseObj(m_pLanConn);
  673. m_pLanConn = NULL;
  674. // reset connection name
  675. m_strConnectionName = c_szEmpty;
  676. AssertSz(m_pnc, "Invalid INetCfg!");
  677. // Note: pguid == NULL when the wizard is requesting the LAN adapter
  678. // to release it's m_pnccAdapter and m_pLanConn members
  679. //
  680. if (SUCCEEDED(hr) && m_pnc && pguid)
  681. {
  682. // 1) Enumerate net adapters and try to find a match with the input GUID
  683. // Save the adapter component in m_pnccAdapter
  684. BOOL fFound = FALSE;
  685. CIterNetCfgComponent nccIter(m_pnc, &GUID_DEVCLASS_NET);
  686. INetCfgComponent* pnccAdapter = NULL;
  687. while (!fFound && SUCCEEDED(hr) &&
  688. (S_OK == (hr = nccIter.HrNext(&pnccAdapter))))
  689. {
  690. GUID guidDev;
  691. hr = pnccAdapter->GetInstanceGuid(&guidDev);
  692. if (S_OK == hr)
  693. {
  694. if (*pguid == guidDev)
  695. {
  696. hr = HrIsLanCapableAdapter(pnccAdapter);
  697. AssertSz((S_OK == hr), "Why is Lan wizard called on a non-Lan capable adapter ?");
  698. if (S_OK == hr)
  699. {
  700. fFound = TRUE;
  701. m_pnccAdapter = pnccAdapter;
  702. AddRefObj(m_pnccAdapter);
  703. }
  704. }
  705. }
  706. ReleaseObj (pnccAdapter);
  707. }
  708. // 2) If we matched an adapter successfully, set it to the UI dialog
  709. if ((fFound) && (S_OK == hr))
  710. {
  711. Assert(m_pnccAdapter);
  712. if (m_pWizPage)
  713. {
  714. m_pWizPage->SetNetcfg(m_pnc);
  715. m_pWizPage->SetAdapter(m_pnccAdapter);
  716. }
  717. }
  718. else
  719. {
  720. hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
  721. }
  722. }
  723. TraceError("CLanConnectionUi::SetDeviceComponent", hr);
  724. return hr;
  725. }
  726. //
  727. // INetLanConnectionUiInfo
  728. //
  729. //+---------------------------------------------------------------------------
  730. //
  731. // Member: CLanConnectionUi::GetDeviceGuid
  732. //
  733. // Purpose: Returns the device GUID associated with this connection
  734. //
  735. // Arguments:
  736. // pguid [out] Returns GUID
  737. //
  738. // Returns: S_OK if success, OLE or Win32 error code otherwise
  739. //
  740. // Author: danielwe 13 Nov 1997
  741. //
  742. // Notes:
  743. //
  744. STDMETHODIMP CLanConnectionUi::GetDeviceGuid(GUID *pguid)
  745. {
  746. HRESULT hr = S_OK;
  747. if (!pguid)
  748. {
  749. hr = E_POINTER;
  750. }
  751. else
  752. {
  753. // $REVIEW(tongl 11/29/97): when called from Lan wizard, the
  754. // m_pconn has not been set yet, but the device guid is kept
  755. // in m_pnccAdapter. So I added the if-else below.
  756. if (m_pconn) // called from property UI
  757. {
  758. INetLanConnection * plan;
  759. hr = HrQIAndSetProxyBlanket(m_pconn, &plan);
  760. if (SUCCEEDED(hr))
  761. {
  762. hr = plan->GetDeviceGuid(pguid);
  763. ReleaseObj(plan);
  764. }
  765. }
  766. else // called from wizard UI
  767. {
  768. AssertSz(m_pnccAdapter, "If called from wizard, the device should have been set.");
  769. if (m_pnccAdapter)
  770. {
  771. m_pnccAdapter->GetInstanceGuid(pguid);
  772. }
  773. else
  774. {
  775. hr = E_FAIL;
  776. }
  777. }
  778. }
  779. TraceError("CLanConnectionUi::GetDeviceGuid", hr);
  780. return hr;
  781. }
  782. //
  783. // INetConnectionUiLock
  784. //
  785. //+---------------------------------------------------------------------------
  786. //
  787. // Member: CLanConnectionUi::QueryLock
  788. //
  789. // Purpose: Causes the UI object to attempt to get the INetCfg write lock.
  790. //
  791. // Arguments:
  792. // ppszwLockHolder [out] Description of component that holds the
  793. // write lock in the event that it couldn't be
  794. // obtained.
  795. //
  796. // Returns: S_OK if success, S_FALSE if write lock couldn't be obtained,
  797. // OLE or Win32 error otherwise
  798. //
  799. // Author: danielwe 13 Nov 1997
  800. //
  801. // Notes:
  802. //
  803. STDMETHODIMP CLanConnectionUi::QueryLock(PWSTR* ppszwLockHolder)
  804. {
  805. HRESULT hr = S_OK;
  806. if (!ppszwLockHolder)
  807. {
  808. hr = E_POINTER;
  809. }
  810. else
  811. {
  812. INetCfgLock * pnclock;
  813. AssertSz(!m_pnc, "We're assuming this is in the property sheet "
  814. "context and we don't yet have an INetCfg!");
  815. *ppszwLockHolder = NULL;
  816. // Instantiate an INetCfg
  817. hr = CoCreateInstance(
  818. CLSID_CNetCfg,
  819. NULL,
  820. CLSCTX_INPROC_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  821. IID_INetCfg,
  822. reinterpret_cast<LPVOID *>(&m_pnc));
  823. TraceHr(ttidError, FAL, hr, FALSE, "CoCreateInstance");
  824. if (SUCCEEDED(hr))
  825. {
  826. // Get the locking interface
  827. hr = m_pnc->QueryInterface(IID_INetCfgLock,
  828. reinterpret_cast<LPVOID *>(&pnclock));
  829. if (SUCCEEDED(hr))
  830. {
  831. // Attempt to lock the INetCfg for read/write
  832. hr = pnclock->AcquireWriteLock(0,
  833. SzLoadIds(IDS_LANUI_LOCK_DESC), ppszwLockHolder);
  834. ReleaseObj(pnclock);
  835. if (NETCFG_E_NEED_REBOOT == hr)
  836. {
  837. // Can't make any changes because we are pending a reboot.
  838. m_fReadOnly = TRUE;
  839. m_fNeedReboot = TRUE;
  840. hr = S_OK;
  841. }
  842. else if(E_ACCESSDENIED == hr)
  843. {
  844. // user not logged on as admin
  845. //
  846. m_fReadOnly = TRUE;
  847. m_fAccessDenied = TRUE;
  848. hr = S_OK;
  849. }
  850. else if (S_FALSE == hr)
  851. {
  852. // We don't have sufficent rights
  853. //
  854. m_fReadOnly = TRUE;
  855. hr = S_OK;
  856. }
  857. }
  858. }
  859. }
  860. TraceError("CLanConnectionUi::QueryLock", (S_FALSE == hr) ? S_OK : hr);
  861. return hr;
  862. }