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.

5074 lines
142 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: L A N U I . C P P
  7. //
  8. // Contents: Lan connection object UI
  9. //
  10. // Notes:
  11. //
  12. // Author: danielwe 16 Oct 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "devdatatip.h"
  18. #include "lancmn.h"
  19. #include "lanui.h"
  20. #include "ncnetcfg.h"
  21. #include "ncnetcon.h"
  22. #include "ncperms.h"
  23. #include "ncsetup.h"
  24. #include "ncstring.h"
  25. #include "ncsvc.h"
  26. #include "ncui.h"
  27. #include "util.h"
  28. #include <raserror.h>
  29. #include <raseapif.h>
  30. #include "lanhelp.h"
  31. #include "ncreg.h"
  32. #include "iphlpapi.h"
  33. #include "beacon.h"
  34. #include "htmlhelp.h"
  35. #include "lm.h"
  36. #include <clusapi.h>
  37. #include <wzcsapi.h>
  38. extern const WCHAR c_szEmpty[];
  39. extern const WCHAR c_szNetCfgHelpFile[];
  40. extern const WCHAR c_szInfId_MS_AppleTalk[];
  41. extern const WCHAR c_szInfId_MS_NWIPX[];
  42. extern const WCHAR c_szInfId_MS_NetMon[];
  43. extern const WCHAR c_szInfId_MS_TCPIP[];
  44. extern const WCHAR c_szInfId_MS_PSched[];
  45. static BOOL g_fReentrancyCheck = FALSE;
  46. static TCHAR g_pszFirewallRegKey[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\HomeNetworking\\PersonalFirewall");
  47. static TCHAR g_pszDisableFirewallWarningValue[] = TEXT("ShowDisableFirewallWarning");
  48. static const CLSID CLSID_NetGroupPolicies =
  49. {0xBA126AD8,0x2166,0x11D1,{0xB1,0xD0,0x00,0x80,0x5F,0xC1,0x27,0x0E}};
  50. //+---------------------------------------------------------------------------
  51. //
  52. // Function: HrDisplayAddComponentDialog
  53. //
  54. // Purpose: Display the add component dialog box and add whatever the user
  55. // selects.
  56. //
  57. // Arguments:
  58. //
  59. // Returns: S_OK if added, S_FALSE if the user cancelled, NETCFG_S_REBOOT
  60. // if a reboot is required
  61. //
  62. // Author: danielwe 15 Dec 1997
  63. //
  64. // Notes: This function is called from RASDLG.DLL for the Networking
  65. // tab of the RAS entry property sheet.
  66. //
  67. HRESULT
  68. HrDisplayAddComponentDialog (
  69. HWND hwndParent,
  70. INetCfg* pnc,
  71. CI_FILTER_INFO* pcfi)
  72. {
  73. HRESULT hr;
  74. if (hwndParent && !IsWindow (hwndParent))
  75. {
  76. hr = E_INVALIDARG;
  77. }
  78. else if (!pnc)
  79. {
  80. hr = E_POINTER;
  81. }
  82. else
  83. {
  84. CLanAddComponentDlg dlg(pnc, pcfi, g_aHelpIDs_IDD_LAN_COMPONENT_ADD);
  85. int nRet = dlg.DoModal(hwndParent);
  86. hr = static_cast<HRESULT>(nRet);
  87. }
  88. TraceError("HrDisplayAddComponentDialog", (S_FALSE == hr) ? S_OK : hr);
  89. return hr;
  90. }
  91. //+---------------------------------------------------------------------------
  92. //
  93. // Function: HrQueryUserAndRemoveComponent
  94. //
  95. // Purpose: Ask the user if its okay to remove the specified component
  96. // and remove it if he/she inidcates yes.
  97. //
  98. // Arguments:
  99. //
  100. // Returns: S_OK if removed, S_FALSE if the user cancelled, NETCFG_S_REBOOT
  101. // if a reboot is required
  102. //
  103. // Author: shaunco 30 Dec 1997
  104. //
  105. // Notes: This function is called from RASDLG.DLL for the Networking
  106. // tab of the RAS entry property sheet.
  107. //
  108. HRESULT
  109. HrQueryUserAndRemoveComponent (
  110. HWND hwndParent,
  111. INetCfg* pnc,
  112. INetCfgComponent* pncc)
  113. {
  114. HRESULT hr;
  115. if (hwndParent && !IsWindow (hwndParent))
  116. {
  117. hr = E_INVALIDARG;
  118. }
  119. else if (!pnc || !pncc)
  120. {
  121. hr = E_POINTER;
  122. }
  123. else
  124. {
  125. PWSTR pszwName;
  126. hr = pncc->GetDisplayName(&pszwName);
  127. if (SUCCEEDED(hr))
  128. {
  129. Assert(pszwName);
  130. BOOL fProceed = TRUE;
  131. // Special case for RAS and TCP/IP removal. If there
  132. // are active ras connections, the user has to disconnect
  133. // them all first before TCP/IP can be removed.
  134. //
  135. PWSTR pszwId;
  136. hr = pncc->GetId (&pszwId);
  137. if (SUCCEEDED(hr))
  138. {
  139. if ((FEqualComponentId (c_szInfId_MS_TCPIP, pszwId) ||
  140. FEqualComponentId (c_szInfId_MS_NWIPX, pszwId) ||
  141. FEqualComponentId (c_szInfId_MS_PSched, pszwId) ||
  142. FEqualComponentId (c_szInfId_MS_AppleTalk, pszwId) ||
  143. FEqualComponentId (c_szInfId_MS_NetMon, pszwId))
  144. && FExistActiveRasConnections ())
  145. {
  146. NcMsgBoxWithVarCaption(_Module.GetResourceInstance(),
  147. hwndParent,
  148. IDS_LAN_REMOVE_CAPTION, pszwName,
  149. IDS_LANUI_REQUIRE_DISCONNECT_REMOVE,
  150. MB_ICONERROR | MB_OK);
  151. fProceed = FALSE;
  152. }
  153. CoTaskMemFree (pszwId);
  154. }
  155. if (fProceed)
  156. {
  157. HCURSOR hCur = NULL;
  158. // Query the user about removing the component
  159. //
  160. int nRet = NcMsgBoxWithVarCaption(_Module.GetResourceInstance(),
  161. hwndParent, IDS_LAN_REMOVE_CAPTION,
  162. pszwName, IDS_LAN_REMOVE_WARNING,
  163. MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2,
  164. pszwName);
  165. if (nRet == IDYES)
  166. {
  167. OBO_TOKEN OboToken;
  168. ZeroMemory (&OboToken, sizeof(OboToken));
  169. OboToken.Type = OBO_USER;
  170. PWSTR mszwRefs = NULL;
  171. hCur = BeginWaitCursor();
  172. hr = HrRemoveComponent(pnc, pncc, &OboToken, &mszwRefs);
  173. if (NETCFG_S_STILL_REFERENCED == hr)
  174. {
  175. static const WCHAR c_szCRLF[] = L"\r\n";
  176. tstring strRefs = c_szCRLF;
  177. PWSTR szwRef = mszwRefs;
  178. AssertSz(mszwRefs, "This can't be NULL!");
  179. while (*szwRef)
  180. {
  181. strRefs += c_szCRLF;
  182. strRefs += szwRef;
  183. szwRef += lstrlenW(szwRef) + 1;
  184. }
  185. LvReportError(IDS_LANUI_STILL_REFERENCED, hwndParent,
  186. pszwName, strRefs.c_str());
  187. CoTaskMemFree(mszwRefs);
  188. }
  189. // If the remove succeeded commit the changes
  190. //
  191. if (SUCCEEDED(hr))
  192. {
  193. g_fReentrancyCheck = TRUE;
  194. // Commit the changes
  195. HRESULT hrTmp = pnc->Apply();
  196. g_fReentrancyCheck = FALSE;
  197. if (S_OK != hrTmp)
  198. {
  199. // Propigate the error
  200. //
  201. hr = hrTmp;
  202. if (FAILED(hr))
  203. pnc->Cancel();
  204. }
  205. }
  206. if (FAILED(hr))
  207. {
  208. if (NETCFG_E_ACTIVE_RAS_CONNECTIONS == hr)
  209. {
  210. LvReportError(IDS_LANUI_REQUIRE_DISCONNECT_REMOVE, hwndParent,
  211. pszwName, NULL);
  212. }
  213. else if (NETCFG_E_NEED_REBOOT == hr)
  214. {
  215. LvReportError(IDS_LANUI_REQUIRE_REBOOT_REMOVE, hwndParent,
  216. pszwName, NULL);
  217. }
  218. else
  219. {
  220. LvReportErrorHr(hr, IDS_LANUI_GENERIC_REMOVE_ERROR,
  221. hwndParent, pszwName);
  222. }
  223. }
  224. }
  225. else
  226. {
  227. hr = S_FALSE;
  228. }
  229. EndWaitCursor(hCur);
  230. }
  231. CoTaskMemFree(pszwName);
  232. }
  233. }
  234. TraceError("HrQueryUserAndRemoveComponent",
  235. (S_FALSE == hr || NETCFG_S_STILL_REFERENCED == hr ||
  236. NETCFG_S_REBOOT) ? S_OK : hr);
  237. return hr;
  238. }
  239. //+---------------------------------------------------------------------------
  240. //
  241. // Function: HrQueryUserForReboot
  242. //
  243. // Purpose: Query the user to reboot. If he/she chooses yes, a reboot
  244. // is initiated.
  245. //
  246. // Arguments:
  247. // hwndParent [in] Parent window handle.
  248. // pszCaption [in] Caption text to use.
  249. // dwFlags [in] Control flags (QUFR_PROMPT | QUFR_REBOOT)
  250. //
  251. // Returns: S_OK if a reboot is initiated, S_FALSE if the user
  252. // didn't want to, or an error code otherwise.
  253. //
  254. // Author: shaunco 2 Jan 1998
  255. //
  256. // Notes:
  257. //
  258. HRESULT
  259. HrQueryUserForReboot (
  260. HWND hwndParent,
  261. PCWSTR pszCaption,
  262. DWORD dwFlags)
  263. {
  264. TraceFileFunc(ttidLanUi);
  265. PCWSTR pszText = SzLoadString(_Module.GetResourceInstance(),
  266. IDS_REBOOT_REQUIRED);
  267. HRESULT hr = HrNcQueryUserForRebootEx (hwndParent,
  268. pszCaption, pszText, dwFlags);
  269. TraceError("HrQueryUserForReboot", hr);
  270. return hr;
  271. }
  272. HRESULT CNetConnectionUiUtilities::QueryUserAndRemoveComponent(
  273. HWND hwndParent,
  274. INetCfg* pnc,
  275. INetCfgComponent* pncc)
  276. {
  277. TraceFileFunc(ttidLanUi);
  278. return HrQueryUserAndRemoveComponent (hwndParent, pnc, pncc);
  279. }
  280. HRESULT CNetConnectionUiUtilities::QueryUserForReboot(
  281. HWND hwndParent,
  282. PCWSTR pszCaption,
  283. DWORD dwFlags)
  284. {
  285. TraceFileFunc(ttidLanUi);
  286. return HrQueryUserForReboot (hwndParent, pszCaption, dwFlags);
  287. }
  288. HRESULT CNetConnectionUiUtilities::DisplayAddComponentDialog (
  289. HWND hwndParent,
  290. INetCfg* pnc,
  291. CI_FILTER_INFO* pcfi)
  292. {
  293. TraceFileFunc(ttidLanUi);
  294. return HrDisplayAddComponentDialog(hwndParent, pnc, pcfi);
  295. }
  296. BOOL CNetConnectionUiUtilities::UserHasPermission(DWORD dwPerm)
  297. {
  298. TraceFileFunc(ttidLanUi);
  299. BOOL fPermission = FALSE;
  300. if (dwPerm == NCPERM_AllowNetBridge_NLA || dwPerm == NCPERM_PersonalFirewallConfig ||
  301. dwPerm == NCPERM_ICSClientApp || dwPerm == NCPERM_ShowSharedAccessUi)
  302. {
  303. HRESULT hr;
  304. INetMachinePolicies* pMachinePolicy;
  305. hr = CoCreateInstance(CLSID_NetGroupPolicies, NULL,
  306. CLSCTX_SERVER, IID_INetMachinePolicies,
  307. reinterpret_cast<void **>(&pMachinePolicy));
  308. if (SUCCEEDED(hr))
  309. {
  310. hr = pMachinePolicy->VerifyPermission(dwPerm, &fPermission);
  311. pMachinePolicy->Release();
  312. }
  313. }
  314. else
  315. {
  316. fPermission = FHasPermission(dwPerm);
  317. }
  318. return fPermission;
  319. }
  320. //
  321. // Connect UI dialog
  322. //
  323. //+---------------------------------------------------------------------------
  324. //
  325. // Member: CLanConnectionUiDlg::OnInitDialog
  326. //
  327. // Purpose: Handles the WM_INITDIALOG message.
  328. //
  329. // Arguments:
  330. // uMsg []
  331. // wParam []
  332. // lParam []
  333. // bHandled []
  334. //
  335. // Returns: TRUE
  336. //
  337. // Author: danielwe 16 Oct 1997
  338. //
  339. // Notes:
  340. //
  341. LRESULT CLanConnectionUiDlg::OnInitDialog(UINT uMsg, WPARAM wParam,
  342. LPARAM lParam, BOOL& bHandled)
  343. {
  344. TraceFileFunc(ttidLanUi);
  345. HRESULT hr = S_OK;
  346. NETCON_PROPERTIES* pProps;
  347. AssertSz(m_pconn, "No connection object in dialog!");
  348. hr = m_pconn->GetProperties(&pProps);
  349. if (SUCCEEDED(hr))
  350. {
  351. SetDlgItemText(IDC_TXT_Caption, SzLoadIds(IDS_LAN_CONNECT_CAPTION));
  352. SetWindowText(pProps->pszwName);
  353. HICON hLanIconSmall;
  354. HICON hLanIconBig;
  355. hr = HrGetIconFromMediaType(GetSystemMetrics(SM_CXSMICON), NCM_LAN, NCSM_LAN, 7, 0, &hLanIconSmall);
  356. if (SUCCEEDED(hr))
  357. {
  358. hr = HrGetIconFromMediaType(GetSystemMetrics(SM_CXICON), NCM_LAN, NCSM_LAN, 7, 0, &hLanIconBig);
  359. if (SUCCEEDED(hr))
  360. {
  361. SetIcon(hLanIconSmall, FALSE);
  362. SetIcon(hLanIconBig, TRUE);
  363. SendDlgItemMessage(IDI_Device_Icon, STM_SETICON, reinterpret_cast<WPARAM>(hLanIconBig), 0);
  364. }
  365. }
  366. FreeNetconProperties(pProps);
  367. }
  368. return TRUE;
  369. }
  370. //+---------------------------------------------------------------------------
  371. //
  372. // Function: HrGetDeviceIcon
  373. //
  374. // Purpose: Returns the icon associated with network devices
  375. //
  376. // Arguments:
  377. // phicon [out] Returns HICON
  378. //
  379. // Returns: S_OK if success, SetupAPI or Win32 error otherwise
  380. //
  381. // Author: danielwe 12 Nov 1997
  382. //
  383. // Notes:
  384. //
  385. HRESULT HrGetDeviceIcon(HICON *phicon)
  386. {
  387. TraceFileFunc(ttidLanUi);
  388. SP_CLASSIMAGELIST_DATA cild;
  389. Assert(phicon);
  390. *phicon = NULL;
  391. HRESULT hr = HrSetupDiGetClassImageList(&cild);
  392. if (SUCCEEDED(hr))
  393. {
  394. INT iImage;
  395. hr = HrSetupDiGetClassImageIndex(&cild,
  396. const_cast<GUID *>(&GUID_DEVCLASS_NET),
  397. &iImage);
  398. if (SUCCEEDED(hr))
  399. {
  400. *phicon = ImageList_GetIcon(cild.ImageList, iImage, 0);
  401. }
  402. (void) HrSetupDiDestroyClassImageList(&cild);
  403. }
  404. TraceError("HrGetDeviceIcon", hr);
  405. return hr;
  406. }
  407. //
  408. // CLanNetPage
  409. //
  410. CLanNetPage::CLanNetPage(
  411. IUnknown* punk,
  412. INetCfg* pnc,
  413. INetConnection* pconn,
  414. BOOLEAN fReadOnly,
  415. BOOLEAN fNeedReboot,
  416. BOOLEAN fAccessDenied,
  417. const DWORD * adwHelpIDs)
  418. {
  419. TraceFileFunc(ttidLanUi);
  420. m_pconn = pconn;
  421. m_pnccAdapter = NULL;
  422. m_pnc = pnc;
  423. m_punk = punk;
  424. m_hilCheckIcons = NULL;
  425. m_hPrevCurs = NULL;
  426. m_plan = NULL;
  427. m_fRebootAlreadyRequested = FALSE;
  428. m_fReadOnly = fReadOnly;
  429. m_fNeedReboot = fNeedReboot;
  430. m_fAccessDenied = fAccessDenied;
  431. m_fInitComplete = FALSE;
  432. m_fNetcfgInUse = FALSE;
  433. m_fNoCancel = FALSE;
  434. m_fLockDown = FALSE;
  435. m_adwHelpIDs = adwHelpIDs;
  436. m_fDirty = FALSE;
  437. }
  438. //+---------------------------------------------------------------------------
  439. //
  440. // Member: CLanNetPage::~CLanNetPage
  441. //
  442. // Purpose: Destroys the CLanNetPage object
  443. //
  444. // Arguments:
  445. // (none)
  446. //
  447. // Returns: Nothing
  448. //
  449. // Author: danielwe 25 Feb 1998
  450. //
  451. // Notes:
  452. //
  453. CLanNetPage::~CLanNetPage()
  454. {
  455. TraceFileFunc(ttidLanUi);
  456. // Destroy our check icons
  457. if (m_hilCheckIcons)
  458. {
  459. ImageList_Destroy(m_hilCheckIcons);
  460. }
  461. if (m_pnc)
  462. {
  463. INetCfgLock * pnclock;
  464. if (SUCCEEDED(m_pnc->QueryInterface(IID_INetCfgLock,
  465. (LPVOID *)&pnclock)))
  466. {
  467. (VOID)pnclock->ReleaseWriteLock();
  468. ReleaseObj(pnclock);
  469. }
  470. }
  471. FreeCollectionAndItem(m_listBindingPaths);
  472. ReleaseObj(m_pnccAdapter);
  473. ReleaseObj(m_plan);
  474. }
  475. LRESULT CLanNetPage::OnChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  476. {
  477. m_fDirty = TRUE;
  478. bHandled = FALSE;
  479. return TRUE;
  480. }
  481. //+---------------------------------------------------------------------------
  482. //
  483. // Member: CLanNetPage::OnDeferredInit
  484. //
  485. // Purpose: Handles the WM_DEFERREDINIT message
  486. //
  487. // Arguments:
  488. // uMsg []
  489. // wParam []
  490. // lParam []
  491. // bHandled []
  492. //
  493. // Returns: TRUE
  494. //
  495. // Author: scottbri 20 Oct 1998
  496. //
  497. // Notes:
  498. //
  499. LRESULT CLanNetPage::OnDeferredInit(UINT uMsg, WPARAM wParam,
  500. LPARAM lParam, BOOL& bHandled)
  501. {
  502. TraceFileFunc(ttidLanUi);
  503. HRESULT hr;
  504. CWaitCursor wc;
  505. HWND hwndParent = GetParent();
  506. AssertSz(m_pnc, "INetConnectionUiLock::QueryLock was not called!");
  507. if(NULL != m_handles.m_hList)
  508. {
  509. ::EnableWindow(m_handles.m_hList, TRUE);
  510. }
  511. if(NULL != m_handles.m_hDescription)
  512. {
  513. ::EnableWindow(m_handles.m_hDescription, TRUE);
  514. }
  515. ::UpdateWindow(hwndParent);
  516. hr = m_pnc->Initialize(NULL);
  517. if (S_OK == hr)
  518. {
  519. AssertSz(m_pconn, "No connection object in dialog!");
  520. hr = HrQIAndSetProxyBlanket(m_pconn, &m_plan);
  521. if (SUCCEEDED(hr))
  522. {
  523. LANCON_INFO linfo;
  524. hr = m_plan->GetInfo(LCIF_ALL, &linfo);
  525. if (SUCCEEDED(hr))
  526. {
  527. // Release any old reference
  528. ReleaseObj(m_pnccAdapter);
  529. // This is already AddRef'd so no need to do it here
  530. hr = HrPnccFromGuid(m_pnc, linfo.guid, &m_pnccAdapter);
  531. if (S_OK != hr)
  532. {
  533. #if DBG
  534. WCHAR achGuid[c_cchGuidWithTerm];
  535. ::StringFromGUID2(linfo.guid, achGuid,c_cbGuidWithTerm);
  536. TraceTag(ttidError, "LAN conection has no matching INetCfgComponent for the adapter !!!!!");
  537. TraceTag(ttidError, "GUID = %S", achGuid);
  538. #endif
  539. if(S_FALSE == hr)
  540. {
  541. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  542. }
  543. }
  544. else
  545. {
  546. Assert(m_pnccAdapter);
  547. HICON hicon;
  548. CheckDlgButton(IDC_CHK_ShowIcon, linfo.fShowIcon);
  549. //::EnableWindow(GetDlgItem(IDC_CHK_ShowIcon), !m_fReadOnly);
  550. hr = HrGetDeviceIcon(&hicon);
  551. if (SUCCEEDED(hr))
  552. {
  553. SendDlgItemMessage(IDI_Device_Icon, STM_SETICON,
  554. reinterpret_cast<WPARAM>(hicon), 0);
  555. ::ShowWindow(GetDlgItem(IDI_Device_Icon), SW_SHOW);
  556. AssertSz(hr != S_FALSE, "Adapter not found!?!?");
  557. }
  558. // Ignore any failure getting the icon above. The icon
  559. // in the dialog is by default hidden.
  560. ::UpdateWindow(hwndParent);
  561. hr = InitializeExtendedUI();
  562. // If the UI is readonly, let user know why the controls are
  563. // disabled..
  564. if (m_fNeedReboot)
  565. {
  566. Assert (m_fReadOnly);
  567. NcMsgBox(_Module.GetResourceInstance(),
  568. m_hWnd,
  569. IDS_LAN_CAPTION,
  570. IDS_LANUI_NEEDS_REBOOT,
  571. MB_ICONINFORMATION | MB_OK);
  572. }
  573. else if (m_fAccessDenied)
  574. {
  575. Assert (m_fReadOnly);
  576. NcMsgBox(_Module.GetResourceInstance(),
  577. m_hWnd,
  578. IDS_LAN_CAPTION,
  579. IDS_LANUI_ACCESS_DENIED,
  580. MB_ICONINFORMATION | MB_OK);
  581. }
  582. else if (m_fReadOnly)
  583. {
  584. NcMsgBox(_Module.GetResourceInstance(),
  585. m_hWnd,
  586. IDS_LAN_CAPTION,
  587. IDS_LANUI_READONLY,
  588. MB_ICONINFORMATION | MB_OK);
  589. }
  590. }
  591. // Don't need the name anymore
  592. CoTaskMemFree(linfo.szwConnName);
  593. }
  594. }
  595. }
  596. if (SUCCEEDED(hr))
  597. {
  598. NETCON_PROPERTIES* pProps;
  599. hr = m_pconn->GetProperties(&pProps);
  600. if (SUCCEEDED(hr))
  601. {
  602. // We need to get the bind name and pnp id of this adapter
  603. // so we can collect the information needed by the data tip
  604. // we are about to create.
  605. //
  606. PWSTR pszDevNodeId = NULL;
  607. PWSTR pszBindName = NULL;
  608. (VOID) m_pnccAdapter->GetPnpDevNodeId (&pszDevNodeId);
  609. (VOID) m_pnccAdapter->GetBindName (&pszBindName);
  610. // Now we create a data tip for the adapter description.
  611. // This will display adapter specific information
  612. // like MAC address and physical location.
  613. //
  614. HWND hwndDataTip = NULL;
  615. CreateDeviceDataTip (m_hWnd, &hwndDataTip, IDC_EDT_Adapter,
  616. pszDevNodeId, pszBindName);
  617. // Set the adapter description.
  618. SetDlgItemText(IDC_EDT_Adapter, pProps->pszwDeviceName);
  619. FreeNetconProperties(pProps);
  620. CoTaskMemFree (pszDevNodeId);
  621. CoTaskMemFree (pszBindName);
  622. }
  623. }
  624. ::UpdateWindow(hwndParent);
  625. return 0L;
  626. }
  627. //+---------------------------------------------------------------------------
  628. //
  629. // Member: CLanNetPage::OnPaint
  630. //
  631. // Purpose: Handles the WM_PAINT message
  632. //
  633. // Arguments:
  634. // uMsg []
  635. // wParam []
  636. // lParam []
  637. // bHandled []
  638. //
  639. // Returns: TRUE
  640. //
  641. // Author: danielwe 29 Oct 1997
  642. //
  643. // Notes:
  644. //
  645. LRESULT CLanNetPage::OnPaint(UINT uMsg, WPARAM wParam,
  646. LPARAM lParam, BOOL& bHandled)
  647. {
  648. TraceFileFunc(ttidLanUi);
  649. if (!m_fInitComplete)
  650. {
  651. m_fInitComplete = TRUE;
  652. // Request the deferred init be processed.
  653. //
  654. SetCursor(LoadCursor(NULL, IDC_ARROW));
  655. PostMessage(WM_DEFERREDINIT, 0, 0);
  656. }
  657. bHandled = FALSE;
  658. return 0L;
  659. }
  660. //+---------------------------------------------------------------------------
  661. //
  662. // Member: CLanNetPage::OnInitDialog
  663. //
  664. // Purpose: Handles the WM_INITDIALOG message
  665. //
  666. // Arguments:
  667. // uMsg []
  668. // wParam []
  669. // lParam []
  670. // bHandled []
  671. //
  672. // Returns: TRUE
  673. //
  674. // Author: danielwe 29 Oct 1997
  675. //
  676. // Notes:
  677. //
  678. LRESULT CLanNetPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  679. LPARAM lParam, BOOL& bHandled)
  680. {
  681. TraceFileFunc(ttidLanUi);
  682. m_handles.m_hAdd = GetDlgItem(IDC_PSB_Add);
  683. m_handles.m_hRemove = GetDlgItem(IDC_PSB_Remove);
  684. m_handles.m_hProperty = GetDlgItem(IDC_PSB_Properties);
  685. m_handles.m_hDescription = GetDlgItem(IDC_TXT_Desc);
  686. SetClassLongPtr(m_hWnd, GCLP_HCURSOR, NULL);
  687. SetClassLongPtr(GetParent(), GCLP_HCURSOR, NULL);
  688. // Initially disable all the controls
  689. //
  690. ::EnableWindow(m_handles.m_hAdd, FALSE);
  691. ::EnableWindow(m_handles.m_hRemove, FALSE);
  692. ::EnableWindow(m_handles.m_hProperty, FALSE);
  693. if(NULL != m_handles.m_hDescription)
  694. {
  695. ::EnableWindow(m_handles.m_hDescription, FALSE);
  696. }
  697. if (!FHasPermission(NCPERM_Statistics))
  698. {
  699. ::EnableWindow(GetDlgItem(IDC_CHK_ShowIcon), FALSE);
  700. }
  701. // If this is a readonly sheet, convert cancel to close.
  702. //
  703. // Bug 130602 - There should still be an OK button
  704. // if (m_fReadOnly)
  705. // {
  706. // ::PostMessage(GetParent(), PSM_CANCELTOCLOSE, 0, 0L);
  707. // m_fNoCancel = TRUE;
  708. // }
  709. return TRUE;
  710. }
  711. //+---------------------------------------------------------------------------
  712. //
  713. // Member: CLanNetPage::OnContextMenu
  714. //
  715. // Purpose: When right click a control, bring up help
  716. //
  717. // Arguments: Standard command parameters
  718. //
  719. // Returns: Standard return
  720. //
  721. LRESULT
  722. CLanNetPage::OnContextMenu(UINT uMsg,
  723. WPARAM wParam,
  724. LPARAM lParam,
  725. BOOL& fHandled)
  726. {
  727. TraceFileFunc(ttidLanUi);
  728. if (m_adwHelpIDs != NULL)
  729. {
  730. ::WinHelp(m_hWnd,
  731. c_szNetCfgHelpFile,
  732. HELP_CONTEXTMENU,
  733. (ULONG_PTR)m_adwHelpIDs);
  734. }
  735. return 0;
  736. }
  737. //+---------------------------------------------------------------------------
  738. //
  739. // Member: CLanNetPage::OnHelp
  740. //
  741. // Purpose: When drag context help icon over a control, bring up help
  742. //
  743. // Arguments: Standard command parameters
  744. //
  745. // Returns: Standard return
  746. //
  747. LRESULT
  748. CLanNetPage::OnHelp( UINT uMsg,
  749. WPARAM wParam,
  750. LPARAM lParam,
  751. BOOL& fHandled)
  752. {
  753. TraceFileFunc(ttidLanUi);
  754. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  755. Assert(lphi);
  756. if ((m_adwHelpIDs != NULL) && (HELPINFO_WINDOW == lphi->iContextType))
  757. {
  758. ::WinHelp(static_cast<HWND>(lphi->hItemHandle),
  759. c_szNetCfgHelpFile,
  760. HELP_WM_HELP,
  761. (ULONG_PTR)m_adwHelpIDs);
  762. }
  763. return 0;
  764. }
  765. //+---------------------------------------------------------------------------
  766. //
  767. // Member: CLanNetPage::OnDestroy
  768. //
  769. // Purpose: Called when the dialog page is destroyed
  770. //
  771. // Arguments:
  772. // uMsg []
  773. // wParam []
  774. // lParam []
  775. // bHandled []
  776. //
  777. // Returns:
  778. //
  779. // Author: danielwe 2 Feb 1998
  780. //
  781. // Notes:
  782. //
  783. LRESULT CLanNetPage::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam,
  784. BOOL& bHandled)
  785. {
  786. TraceFileFunc(ttidLanUi);
  787. HICON hIcon;
  788. hIcon = reinterpret_cast<HICON>(SendDlgItemMessage(IDI_Device_Icon, STM_GETICON, 0, 0));
  789. if (hIcon)
  790. {
  791. DestroyIcon(hIcon);
  792. }
  793. UninitializeExtendedUI();
  794. return 0;
  795. }
  796. //+---------------------------------------------------------------------------
  797. //
  798. // Member: CLanNetPage::OnSetCursor
  799. //
  800. // Purpose: Called in response to the WM_SETCURSOR message
  801. //
  802. // Arguments:
  803. // uMsg []
  804. // wParam []
  805. // lParam []
  806. // bHandled []
  807. //
  808. // Returns:
  809. //
  810. // Author: danielwe 2 Jan 1998
  811. //
  812. // Notes:
  813. //
  814. LRESULT CLanNetPage::OnSetCursor(UINT uMsg, WPARAM wParam, LPARAM lParam,
  815. BOOL& bHandled)
  816. {
  817. TraceFileFunc(ttidLanUi);
  818. if (m_hPrevCurs)
  819. {
  820. if (LOWORD(lParam) == HTCLIENT)
  821. {
  822. SetCursor(LoadCursor(NULL, IDC_WAIT));
  823. }
  824. return TRUE;
  825. }
  826. return 0;
  827. }
  828. //+---------------------------------------------------------------------------
  829. //
  830. // Member: CLanNetPage::RequestReboot
  831. //
  832. // Purpose: Request permission to reboot the machine from the user. If
  833. // approved the reboot is performed
  834. //
  835. // Arguments:
  836. //
  837. // Returns:
  838. //
  839. // Author: scottbri 19 Aug 1998
  840. //
  841. // Notes:
  842. //
  843. HRESULT CLanNetPage::HrRequestReboot()
  844. {
  845. TraceFileFunc(ttidLanUi);
  846. HRESULT hr = S_FALSE;
  847. // A reboot is required. Ask the user if it is ok to reboot now
  848. //
  849. hr = HrNcQueryUserForReboot(_Module.GetResourceInstance(),
  850. m_hWnd, IDS_LAN_CAPTION,
  851. IDS_REBOOT_REQUIRED,
  852. QUFR_PROMPT);
  853. if (S_OK == hr)
  854. {
  855. // User requested a reboot, note this for processing in OnApply
  856. // which is triggered by the message posted below
  857. //
  858. m_fRebootAlreadyRequested = TRUE;
  859. // Press the cancel button (changes have already been applied)
  860. // so the appropriate cleanup occurs.
  861. //
  862. ::PostMessage(GetParent(), PSM_PRESSBUTTON, (WPARAM)PSBTN_OK, 0);
  863. }
  864. return hr;
  865. }
  866. //+---------------------------------------------------------------------------
  867. //
  868. // Member: CLanNetPage::OnAddHelper
  869. //
  870. // Purpose: Handles the clicking of the Add button
  871. //
  872. // Arguments:
  873. // wNotifyCode []
  874. // wID []
  875. // hWndCtl []
  876. // bHandled []
  877. //
  878. // Returns:
  879. //
  880. // Author: danielwe 29 Oct 1997
  881. //
  882. // Notes:
  883. //
  884. LRESULT CLanNetPage::OnAddHelper(HWND hwndLV)
  885. {
  886. TraceFileFunc(ttidLanUi);
  887. HRESULT hr = S_OK;
  888. // $REVIEW(tongl 1/6/99): We can't let user do anything till this
  889. // is returned (Raid #258690)
  890. // disable all buttons on this dialog
  891. static const int nrgIdc[] = {IDC_PSB_Add,
  892. IDC_PSB_Remove,
  893. IDC_PSB_Properties};
  894. EnableOrDisableDialogControls(m_hWnd, celems(nrgIdc), nrgIdc, FALSE);
  895. // get window handle to propertysheet
  896. HWND hwndParent=GetParent();
  897. Assert(hwndParent);
  898. ::EnableWindow(::GetDlgItem(hwndParent, IDOK), FALSE);
  899. ::EnableWindow(::GetDlgItem(hwndParent, IDCANCEL), FALSE);
  900. // make sure user can't close the UI till we are done
  901. m_fNetcfgInUse = TRUE;
  902. EnableWindow(FALSE);
  903. hr = HrLvAdd(hwndLV, m_hWnd, m_pnc, m_pnccAdapter, &m_listBindingPaths);
  904. if( S_OK != hr )
  905. {
  906. // If HrLvAdd failed then the adapater was deleted by the CModifyContext::HrApplyIfOkOrCancel function
  907. // Now we have to recreate the adapter
  908. //
  909. HRESULT hrT;
  910. LANCON_INFO linfo;
  911. // Determine the GUID of the adapter
  912. //
  913. hrT = m_plan->GetInfo(LCIF_ALL, &linfo);
  914. if (SUCCEEDED(hrT))
  915. {
  916. // Release any old reference
  917. ReleaseObj(m_pnccAdapter);
  918. // Get the adpater matching the GUID
  919. //
  920. //
  921. hrT = HrPnccFromGuid(m_pnc, linfo.guid, &m_pnccAdapter);
  922. if(SUCCEEDED(hrT))
  923. {
  924. // Refresh the list view
  925. //
  926. hrT = HrRefreshAll(hwndLV, m_pnc, m_pnccAdapter, &m_listBindingPaths);
  927. }
  928. }
  929. }
  930. EnableWindow(TRUE);
  931. if (SUCCEEDED(hr) && (S_FALSE != hr))
  932. {
  933. // Change the Cancel Button to CLOSE (because we committed changes)
  934. //
  935. ::PostMessage(GetParent(), PSM_CANCELTOCLOSE, 0, 0L);
  936. m_fNoCancel = TRUE;
  937. }
  938. if (NETCFG_S_REBOOT == hr)
  939. {
  940. hr = HrRequestReboot();
  941. // The reboot request has been handled
  942. hr = S_OK;
  943. }
  944. else if (S_FALSE == hr)
  945. {
  946. hr = S_OK;
  947. }
  948. // Reset the buttons and the description text based on the changed selection
  949. LvSetButtons(m_hWnd, m_handles, m_fReadOnly, m_punk);
  950. ::EnableWindow(::GetDlgItem(hwndParent, IDOK), TRUE);
  951. if (!m_fNoCancel)
  952. {
  953. ::EnableWindow(::GetDlgItem(hwndParent, IDCANCEL), TRUE);
  954. }
  955. m_fNetcfgInUse = FALSE;
  956. TraceError("CLanNetPage::OnAdd", hr);
  957. return LresFromHr(hr);
  958. }
  959. //+---------------------------------------------------------------------------
  960. //
  961. // Member: CLanNetPage::OnRemove
  962. //
  963. // Purpose: Handles the clicking of the Remove button
  964. //
  965. // Arguments:
  966. // wNotifyCode []
  967. // wID []
  968. // hWndCtl []
  969. // bHandled []
  970. //
  971. // Returns:
  972. //
  973. // Author: danielwe 29 Oct 1997
  974. //
  975. // Notes:
  976. //
  977. LRESULT CLanNetPage::OnRemoveHelper(HWND hwndLV)
  978. {
  979. TraceFileFunc(ttidLanUi);
  980. HRESULT hr = S_OK;
  981. // $REVIEW(tongl 1/6/99): We can't let user do anything till this
  982. // is returned (Raid #258690)
  983. // disable all buttons on this dialog
  984. static const int nrgIdc[] = {IDC_PSB_Add,
  985. IDC_PSB_Remove,
  986. IDC_PSB_Properties};
  987. EnableOrDisableDialogControls(m_hWnd, celems(nrgIdc), nrgIdc, FALSE);
  988. // get window handle to propertysheet
  989. HWND hwndParent=GetParent();
  990. Assert(hwndParent);
  991. ::EnableWindow(::GetDlgItem(hwndParent, IDOK), FALSE);
  992. ::EnableWindow(::GetDlgItem(hwndParent, IDCANCEL), FALSE);
  993. // make sure user can't close the UI till we are done
  994. m_fNetcfgInUse = TRUE;
  995. EnableWindow(FALSE);
  996. hr = HrLvRemove(hwndLV, m_hWnd, m_pnc, m_pnccAdapter,
  997. &m_listBindingPaths);
  998. EnableWindow(TRUE);
  999. if (SUCCEEDED(hr) && (S_FALSE != hr))
  1000. {
  1001. // Change the Cancel Button to CLOSE (because we committed changes)
  1002. //
  1003. ::PostMessage(GetParent(), PSM_CANCELTOCLOSE, 0, 0L);
  1004. m_fNoCancel = TRUE;
  1005. }
  1006. if (S_FALSE == hr)
  1007. {
  1008. hr = S_OK;
  1009. }
  1010. if (NETCFG_S_REBOOT == hr)
  1011. {
  1012. HrRequestReboot();
  1013. // The reboot request has been handled
  1014. hr = S_OK;
  1015. }
  1016. // Reset the buttons and the description text based on the changed selection
  1017. LvSetButtons(m_hWnd, m_handles, m_fReadOnly, m_punk);
  1018. if (!m_fNoCancel)
  1019. {
  1020. ::EnableWindow(::GetDlgItem(hwndParent, IDCANCEL), TRUE);
  1021. }
  1022. ::EnableWindow(::GetDlgItem(hwndParent, IDOK), TRUE);
  1023. m_fNetcfgInUse = FALSE;
  1024. TraceError("CLanNetPage::OnRemove", hr);
  1025. return LresFromHr(hr);
  1026. }
  1027. //+---------------------------------------------------------------------------
  1028. //
  1029. // Member: CLanNetPage::OnProperties
  1030. //
  1031. // Purpose: Handles the clicking of the Properties button
  1032. //
  1033. // Arguments:
  1034. // wNotifyCode []
  1035. // wID []
  1036. // hWndCtl []
  1037. // bHandled []
  1038. //
  1039. // Returns:
  1040. //
  1041. // Author: danielwe 29 Oct 1997
  1042. //
  1043. // Notes:
  1044. //
  1045. LRESULT CLanNetPage::OnPropertiesHelper(HWND hwndLV)
  1046. {
  1047. TraceFileFunc(ttidLanUi);
  1048. HRESULT hr = S_OK;
  1049. BOOL bChanged;
  1050. // $REVIEW(tongl 12/02/98): We can't let user do anything till this
  1051. // is returned (Raid #258690)
  1052. // disable all buttons on this dialog
  1053. static const int nrgIdc[] = {IDC_PSB_Add,
  1054. IDC_PSB_Remove,
  1055. IDC_PSB_Properties};
  1056. EnableOrDisableDialogControls(m_hWnd, celems(nrgIdc), nrgIdc, FALSE);
  1057. // get window handle to propertysheet
  1058. HWND hwndParent=GetParent();
  1059. Assert(hwndParent);
  1060. ::EnableWindow(::GetDlgItem(hwndParent, IDOK), FALSE);
  1061. ::EnableWindow(::GetDlgItem(hwndParent, IDCANCEL), FALSE);
  1062. // make sure user can't close the UI till we are done
  1063. m_fNetcfgInUse = TRUE;
  1064. hr = HrLvProperties(hwndLV, m_hWnd, m_pnc, m_punk,
  1065. m_pnccAdapter, &m_listBindingPaths,
  1066. &bChanged);
  1067. if ( bChanged )
  1068. {
  1069. // Change the Cancel Button to CLOSE (because we committed changes)
  1070. //
  1071. ::PostMessage(GetParent(), PSM_CANCELTOCLOSE, 0, 0L);
  1072. m_fNoCancel = TRUE;
  1073. }
  1074. // Reset the buttons and the description text based on the changed selection
  1075. LvSetButtons(m_hWnd, m_handles, m_fReadOnly, m_punk);
  1076. ::EnableWindow(::GetDlgItem(hwndParent, IDOK), TRUE);
  1077. if (!m_fNoCancel)
  1078. {
  1079. ::EnableWindow(::GetDlgItem(hwndParent, IDCANCEL), TRUE);
  1080. }
  1081. m_fNetcfgInUse = FALSE;
  1082. TraceError("CLanNetPage::OnProperties", hr);
  1083. return LresFromHr(hr);
  1084. }
  1085. //+---------------------------------------------------------------------------
  1086. //
  1087. // Member: CLanNetPage::OnConfigure
  1088. //
  1089. // Purpose: Handles the clicking of the Configure button
  1090. //
  1091. // Arguments:
  1092. // wNotifyCode []
  1093. // wID []
  1094. // hWndCtl []
  1095. // bHandled []
  1096. //
  1097. // Returns:
  1098. //
  1099. // Notes:
  1100. //
  1101. LRESULT CLanNetPage::OnConfigure(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  1102. BOOL& bHandled)
  1103. {
  1104. TraceFileFunc(ttidLanUi);
  1105. HRESULT hr = S_OK;
  1106. BOOL bProceed = TRUE;
  1107. if (m_fDirty)
  1108. {
  1109. bProceed = FALSE;
  1110. LPWSTR szDisplayName;
  1111. NETCON_PROPERTIES *pProps = NULL;
  1112. HRESULT hrT = m_pconn->GetProperties(&pProps);
  1113. if (SUCCEEDED(hrT))
  1114. {
  1115. szDisplayName = pProps->pszwName;
  1116. }
  1117. else
  1118. {
  1119. szDisplayName = const_cast<LPWSTR>(SzLoadIds(IDS_LAN_DEFAULT_CONN_NAME));
  1120. }
  1121. if (IDYES == ::MessageBox(m_hWnd, SzLoadIds(IDS_DIRTY_PROPERTIES), szDisplayName, MB_YESNO))
  1122. {
  1123. bProceed = TRUE;
  1124. }
  1125. if (SUCCEEDED(hrT))
  1126. {
  1127. FreeNetconProperties(pProps);
  1128. }
  1129. }
  1130. if (bProceed)
  1131. {
  1132. hr = RaiseDeviceConfiguration(m_hWnd, m_pnccAdapter);
  1133. PostQuitMessage(0);
  1134. }
  1135. TraceError("CLanNetPage::OnConfigure", hr);
  1136. return LresFromHr(hr);
  1137. }
  1138. //+---------------------------------------------------------------------------
  1139. //
  1140. // Member: CLanNetPage::OnKillActiveHelper
  1141. //
  1142. // Purpose: Called to check warning conditions before the Networking
  1143. // page is going away
  1144. //
  1145. // Arguments:
  1146. // idCtrl []
  1147. // pnmh []
  1148. // bHandled []
  1149. //
  1150. // Returns:
  1151. //
  1152. // Author: tongl 3 Dec 1998
  1153. //
  1154. // Notes:
  1155. //
  1156. LRESULT CLanNetPage::OnKillActiveHelper(HWND hwndLV)
  1157. {
  1158. TraceFileFunc(ttidLanUi);
  1159. BOOL fError;
  1160. fError = m_fNetcfgInUse;
  1161. if (!fError && !m_fReadOnly && !m_fLockDown)
  1162. {
  1163. fError = FValidatePageContents( m_hWnd,
  1164. hwndLV,
  1165. m_pnc,
  1166. m_pnccAdapter,
  1167. &m_listBindingPaths);
  1168. }
  1169. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, fError);
  1170. return fError;
  1171. }
  1172. //+---------------------------------------------------------------------------
  1173. //
  1174. // Member: CLanNetPage::OnApply
  1175. //
  1176. // Purpose: Called when the Networking page is applied
  1177. //
  1178. // Arguments:
  1179. // idCtrl []
  1180. // pnmh []
  1181. // bHandled []
  1182. //
  1183. // Returns:
  1184. //
  1185. // Author: danielwe 29 Oct 1997
  1186. //
  1187. // Notes:
  1188. //
  1189. LRESULT CLanNetPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  1190. {
  1191. TraceFileFunc(ttidLanUi);
  1192. HRESULT hr = S_OK;
  1193. if (g_fReentrancyCheck)
  1194. {
  1195. TraceTag(ttidLanUi, "CLanNetPage::OnApply is being re-entered! "
  1196. "I'm outta here!");
  1197. // Don't allow the automatic EndDialog() to work just yet
  1198. SetWindowLong(DWLP_MSGRESULT, PSNRET_INVALID);
  1199. return TRUE;
  1200. }
  1201. if (!m_fReadOnly)
  1202. {
  1203. m_hPrevCurs = SetCursor(LoadCursor(NULL, IDC_WAIT));
  1204. BOOL fReboot = FALSE;
  1205. // Issue: This function becomes reentrant because INetCfg::Apply()
  1206. // has a message pump in it which causes the PSN_APPLY message to
  1207. // be processed twice. This will happen ONLY if the user double-clicks
  1208. // the OK button.
  1209. g_fReentrancyCheck = TRUE;
  1210. TraceTag(ttidLanUi, "Calling INetCfg::Apply()");
  1211. hr = m_pnc->Apply();
  1212. if (NETCFG_S_REBOOT == hr)
  1213. {
  1214. fReboot = TRUE;
  1215. }
  1216. if (SUCCEEDED(hr))
  1217. {
  1218. TraceTag(ttidLanUi, "INetCfg::Apply() succeeded");
  1219. hr = m_pnc->Uninitialize();
  1220. }
  1221. if (SUCCEEDED(hr))
  1222. {
  1223. if (m_fRebootAlreadyRequested || fReboot)
  1224. {
  1225. DWORD dwFlags = QUFR_REBOOT;
  1226. if (!m_fRebootAlreadyRequested)
  1227. dwFlags |= QUFR_PROMPT;
  1228. (VOID) HrNcQueryUserForReboot(_Module.GetResourceInstance(),
  1229. m_hWnd, IDS_LAN_CAPTION,
  1230. IDS_REBOOT_REQUIRED,
  1231. dwFlags);
  1232. }
  1233. }
  1234. // Normalize result
  1235. if (S_FALSE == hr)
  1236. {
  1237. hr = S_OK;
  1238. }
  1239. if (m_hPrevCurs)
  1240. {
  1241. SetCursor(m_hPrevCurs);
  1242. m_hPrevCurs = NULL;
  1243. }
  1244. // Reset this just in case
  1245. g_fReentrancyCheck = FALSE;
  1246. // On failure tell the user we weren't able to commit all changes
  1247. //
  1248. if (FAILED(hr))
  1249. {
  1250. NcMsgBox(_Module.GetResourceInstance(), m_hWnd, IDS_LAN_CAPTION,
  1251. IDS_LANUI_APPLYFAILED, MB_ICONINFORMATION | MB_OK);
  1252. TraceError("CLanNetPage::OnApply", hr);
  1253. // Eat the error or the user will never be able to leave the dialog
  1254. // (if the cancel button is disabled)
  1255. //
  1256. hr = S_OK;
  1257. }
  1258. } // !fReadOnly
  1259. // Apply "general" properties
  1260. if (SUCCEEDED(hr))
  1261. {
  1262. LANCON_INFO linfo = {0};
  1263. linfo.fShowIcon = IsDlgButtonChecked(IDC_CHK_ShowIcon);
  1264. // Set new value of show icon property
  1265. hr = m_plan->SetInfo(LCIF_ICON, &linfo);
  1266. }
  1267. m_fDirty = FALSE;
  1268. return LresFromHr(hr);
  1269. }
  1270. //+---------------------------------------------------------------------------
  1271. //
  1272. // Member: CLanNetPage::OnCancel
  1273. //
  1274. // Purpose: Called when the Networking page is cancelled.
  1275. //
  1276. // Arguments:
  1277. // idCtrl []
  1278. // pnmh []
  1279. // bHandled []
  1280. //
  1281. // Returns:
  1282. //
  1283. // Author: danielwe 3 Jan 1998
  1284. //
  1285. // Notes: Added the check to see if we are in the middle of
  1286. // installing components, in which case we can't
  1287. // uninitialize INetCfg (Raid #258690).
  1288. //
  1289. LRESULT CLanNetPage::OnCancel(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  1290. {
  1291. TraceFileFunc(ttidLanUi);
  1292. AssertSz(m_pnc, "I need a NetCfg object!");
  1293. if (!m_fNetcfgInUse)
  1294. {
  1295. (VOID) m_pnc->Uninitialize();
  1296. }
  1297. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, m_fNetcfgInUse);
  1298. return m_fNetcfgInUse;
  1299. }
  1300. DWORD WINAPI RaiseDeviceConfigurationThread(LPVOID lpParam)
  1301. {
  1302. const char c_szDevicePropertiesW[] = "DevicePropertiesW";
  1303. const WCHAR c_szDevMgrDll[] = L"devmgr.dll";
  1304. PWSTR pszwPnpDevNodeId = reinterpret_cast<PWSTR>(lpParam);
  1305. Assert(pszwPnpDevNodeId);
  1306. typedef int (STDAPICALLTYPE* NDeviceProperties)(HWND, PCWSTR,
  1307. PCWSTR, BOOL);
  1308. HMODULE hModule;
  1309. NDeviceProperties pfn;
  1310. // Load the Device Manager and get the procedure
  1311. HRESULT hr = HrLoadLibAndGetProc(c_szDevMgrDll, c_szDevicePropertiesW,
  1312. &hModule, reinterpret_cast<FARPROC*>(&pfn));
  1313. if (SUCCEEDED(hr))
  1314. {
  1315. // Bring up the device's properties...
  1316. // This fcn doesn't return anything meaningful so
  1317. // we can ignore it
  1318. (void) (*pfn)(::GetDesktopWindow(), NULL, pszwPnpDevNodeId, FALSE);
  1319. FreeLibrary(hModule); // REVIEW possible uninit var
  1320. }
  1321. CoTaskMemFree(pszwPnpDevNodeId);
  1322. return hr;
  1323. }
  1324. #define COMCTL_IDS_PROPERTIESFOR 0x1042
  1325. HRESULT CLanNetPage::RaiseDeviceConfiguration(HWND hWndParent, INetCfgComponent* pAdapterConfigComponent)
  1326. {
  1327. TraceFileFunc(ttidLanUi);
  1328. HRESULT hr = E_INVALIDARG;
  1329. // Get the PnpId of the adapter
  1330. if (pAdapterConfigComponent)
  1331. {
  1332. PWSTR pszwPnpDevNodeId;
  1333. hr = pAdapterConfigComponent->GetPnpDevNodeId(&pszwPnpDevNodeId);
  1334. if (SUCCEEDED(hr))
  1335. {
  1336. WCHAR szWindowTitle[MAX_PATH];
  1337. ZeroMemory(szWindowTitle, MAX_PATH);
  1338. PWSTR pszwDisplayName;
  1339. HRESULT hrT = pAdapterConfigComponent->GetDisplayName(&pszwDisplayName);
  1340. if (SUCCEEDED(hrT))
  1341. {
  1342. HMODULE hComCtl32 = GetModuleHandle(L"comctl32.dll");
  1343. if (hComCtl32)
  1344. {
  1345. WCHAR szPropertiesFor[MAX_PATH];
  1346. if (LoadString(hComCtl32, COMCTL_IDS_PROPERTIESFOR, szPropertiesFor, MAX_PATH))
  1347. {
  1348. wsprintf(szWindowTitle, szPropertiesFor, pszwDisplayName);
  1349. }
  1350. }
  1351. }
  1352. if (*szWindowTitle)
  1353. {
  1354. HWND hWndDevNode = FindWindow(NULL, szWindowTitle);
  1355. if (hWndDevNode && IsWindow(hWndDevNode))
  1356. {
  1357. SetForegroundWindow(hWndDevNode);
  1358. }
  1359. else
  1360. {
  1361. CreateThread(NULL, STACK_SIZE_TINY, RaiseDeviceConfigurationThread, pszwPnpDevNodeId, 0, NULL);
  1362. DWORD dwTries = 120;
  1363. while (!FindWindow(NULL, szWindowTitle) && dwTries--)
  1364. {
  1365. Sleep(500);
  1366. }
  1367. CoTaskMemFree(pszwDisplayName);
  1368. }
  1369. }
  1370. else
  1371. {
  1372. CreateThread(NULL, STACK_SIZE_TINY, RaiseDeviceConfigurationThread, pszwPnpDevNodeId, 0, NULL);
  1373. }
  1374. }
  1375. }
  1376. return hr;
  1377. }
  1378. //
  1379. // CLanNetNormalPage
  1380. //
  1381. CLanNetNormalPage::CLanNetNormalPage(
  1382. IUnknown* punk,
  1383. INetCfg* pnc,
  1384. INetConnection* pconn,
  1385. BOOLEAN fReadOnly,
  1386. BOOLEAN fNeedReboot,
  1387. BOOLEAN fAccessDenied,
  1388. const DWORD * adwHelpIDs) : CLanNetPage(punk, pnc, pconn, fReadOnly, fNeedReboot, fAccessDenied, adwHelpIDs)
  1389. {
  1390. TraceFileFunc(ttidLanUi);
  1391. }
  1392. LRESULT CLanNetNormalPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  1393. LPARAM lParam, BOOL& bHandled)
  1394. {
  1395. TraceFileFunc(ttidLanUi);
  1396. m_handles.m_hList = m_hwndLV = GetDlgItem(IDC_LVW_Net_Components);
  1397. ::EnableWindow(m_hwndLV, FALSE);
  1398. return CLanNetPage::OnInitDialog(uMsg, wParam, lParam, bHandled);
  1399. }
  1400. LRESULT CLanNetNormalPage::OnAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1401. {
  1402. TraceFileFunc(ttidLanUi);
  1403. m_fDirty = TRUE;
  1404. return OnAddHelper(m_hwndLV);
  1405. }
  1406. LRESULT CLanNetNormalPage::OnRemove(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1407. {
  1408. TraceFileFunc(ttidLanUi);
  1409. m_fDirty = TRUE;
  1410. return OnRemoveHelper(m_hwndLV);
  1411. }
  1412. LRESULT CLanNetNormalPage::OnProperties(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1413. {
  1414. TraceFileFunc(ttidLanUi);
  1415. m_fDirty = TRUE;
  1416. return OnPropertiesHelper(m_hwndLV);
  1417. }
  1418. LRESULT CLanNetNormalPage::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  1419. {
  1420. TraceFileFunc(ttidLanUi);
  1421. return OnKillActiveHelper(m_hwndLV);
  1422. }
  1423. //+---------------------------------------------------------------------------
  1424. //
  1425. // Member: CLanNetPage::OnDeleteItem
  1426. //
  1427. // Purpose: Called when the LVN_DELETEITEM message is received
  1428. //
  1429. // Arguments:
  1430. // idCtrl []
  1431. // pnmh []
  1432. // bHandled []
  1433. //
  1434. // Returns:
  1435. //
  1436. // Author: danielwe 3 Nov 1997
  1437. //
  1438. // Notes:
  1439. //
  1440. LRESULT CLanNetNormalPage::OnDeleteItem(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  1441. {
  1442. TraceFileFunc(ttidLanUi);
  1443. NM_LISTVIEW * pnmlv = reinterpret_cast<NM_LISTVIEW *>(pnmh);
  1444. Assert(IDC_LVW_Net_Components == idCtrl);
  1445. LvDeleteItem(m_hwndLV, pnmlv->iItem);
  1446. m_fDirty = TRUE;
  1447. return 0;
  1448. }
  1449. //+---------------------------------------------------------------------------
  1450. //
  1451. // Member: CLanNetPage::OnClick
  1452. //
  1453. // Purpose: Called in response to the NM_CLICK message
  1454. //
  1455. // Arguments:
  1456. // idCtrl []
  1457. // pnmh []
  1458. // fHandled []
  1459. //
  1460. // Returns:
  1461. //
  1462. // Author: danielwe 1 Dec 1997
  1463. //
  1464. // Notes:
  1465. //
  1466. LRESULT CLanNetNormalPage::OnClick(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  1467. {
  1468. TraceFileFunc(ttidLanUi);
  1469. OnListClick(m_hwndLV, m_hWnd, m_pnc, m_punk,
  1470. m_pnccAdapter, &m_listBindingPaths, FALSE, m_fReadOnly);
  1471. m_fDirty = TRUE;
  1472. return 0;
  1473. }
  1474. //+---------------------------------------------------------------------------
  1475. //
  1476. // Member: CLanNetPage::OnDbClick
  1477. //
  1478. // Purpose: Called in response to the NM_DBLCLK message
  1479. //
  1480. // Arguments:
  1481. // idCtrl []
  1482. // pnmh []
  1483. // fHandled []
  1484. //
  1485. // Returns:
  1486. //
  1487. // Author: danielwe 1 Dec 1997
  1488. //
  1489. // Notes:
  1490. //
  1491. LRESULT CLanNetNormalPage::OnDbClick(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  1492. {
  1493. TraceFileFunc(ttidLanUi);
  1494. OnListClick(m_hwndLV, m_hWnd, m_pnc, m_punk,
  1495. m_pnccAdapter, &m_listBindingPaths, TRUE, m_fReadOnly);
  1496. m_fDirty = TRUE;
  1497. return 0;
  1498. }
  1499. //+---------------------------------------------------------------------------
  1500. //
  1501. // Member: CLanNetPage::OnKeyDown
  1502. //
  1503. // Purpose: Called in response to the LVN_KEYDOWN message
  1504. //
  1505. // Arguments:
  1506. // idCtrl []
  1507. // pnmh []
  1508. // fHandled []
  1509. //
  1510. // Returns:
  1511. //
  1512. // Author: danielwe 1 Dec 1997
  1513. //
  1514. // Notes:
  1515. //
  1516. LRESULT CLanNetNormalPage::OnKeyDown(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  1517. {
  1518. TraceFileFunc(ttidLanUi);
  1519. if (!m_fReadOnly)
  1520. {
  1521. LV_KEYDOWN* plvkd = (LV_KEYDOWN*)pnmh;
  1522. OnListKeyDown(m_hwndLV, &m_listBindingPaths, plvkd->wVKey);
  1523. }
  1524. return 0;
  1525. }
  1526. //+---------------------------------------------------------------------------
  1527. //
  1528. // Member: CLanNetPage::OnItemChanged
  1529. //
  1530. // Purpose: Called when the LVN_ITEMCHANGED message is received
  1531. //
  1532. // Arguments:
  1533. // idCtrl []
  1534. // pnmh []
  1535. // bHandled []
  1536. //
  1537. // Returns:
  1538. //
  1539. // Author: danielwe 10 Nov 1997
  1540. //
  1541. // Notes:
  1542. //
  1543. LRESULT CLanNetNormalPage::OnItemChanged(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  1544. {
  1545. TraceFileFunc(ttidLanUi);
  1546. NM_LISTVIEW * pnmlv = reinterpret_cast<NM_LISTVIEW *>(pnmh);
  1547. Assert(pnmlv);
  1548. // Reset the buttons and the description text based on the changed selection
  1549. LvSetButtons(m_hWnd, m_handles, m_fReadOnly, m_punk);
  1550. return 0;
  1551. }
  1552. HRESULT CLanNetNormalPage::InitializeExtendedUI()
  1553. {
  1554. TraceFileFunc(ttidLanUi);
  1555. HRESULT hResult = HrInitListView(m_hwndLV, m_pnc, m_pnccAdapter,
  1556. &m_listBindingPaths,
  1557. &m_hilCheckIcons);
  1558. // Reset the buttons and the description text based on the changed selection
  1559. LvSetButtons(m_hWnd, m_handles, m_fReadOnly, m_punk);
  1560. return hResult;
  1561. }
  1562. HRESULT CLanNetNormalPage::UninitializeExtendedUI()
  1563. {
  1564. TraceFileFunc(ttidLanUi);
  1565. UninitListView(m_hwndLV);
  1566. return S_OK;
  1567. }
  1568. //
  1569. // CLanNetBridgedPage
  1570. //
  1571. CLanNetBridgedPage::CLanNetBridgedPage(
  1572. IUnknown* punk,
  1573. INetCfg* pnc,
  1574. INetConnection* pconn,
  1575. BOOLEAN fReadOnly,
  1576. BOOLEAN fNeedReboot,
  1577. BOOLEAN fAccessDenied,
  1578. const DWORD * adwHelpIDs) : CLanNetPage(punk, pnc, pconn, fReadOnly, fNeedReboot, fAccessDenied, adwHelpIDs)
  1579. {
  1580. TraceFileFunc(ttidLanUi);
  1581. }
  1582. LRESULT CLanNetBridgedPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  1583. LPARAM lParam, BOOL& bHandled)
  1584. {
  1585. TraceFileFunc(ttidLanUi);
  1586. m_handles.m_hList = NULL;
  1587. return CLanNetPage::OnInitDialog(uMsg, wParam, lParam, bHandled);
  1588. }
  1589. //
  1590. // CLanNetNetworkBridgePage
  1591. //
  1592. CLanNetNetworkBridgePage::CLanNetNetworkBridgePage(
  1593. IUnknown* punk,
  1594. INetCfg* pnc,
  1595. INetConnection* pconn,
  1596. BOOLEAN fReadOnly,
  1597. BOOLEAN fNeedReboot,
  1598. BOOLEAN fAccessDenied,
  1599. const DWORD * adwHelpIDs) : CLanNetPage(punk, pnc, pconn, fReadOnly, fNeedReboot, fAccessDenied, adwHelpIDs)
  1600. {
  1601. TraceFileFunc(ttidLanUi);
  1602. m_hAdaptersListView = NULL;
  1603. m_hAdaptersListImageList = NULL;
  1604. }
  1605. LRESULT CLanNetNetworkBridgePage::OnInitDialog(UINT uMsg, WPARAM wParam,
  1606. LPARAM lParam, BOOL& bHandled)
  1607. {
  1608. TraceFileFunc(ttidLanUi);
  1609. m_handles.m_hList = m_hwndLV = GetDlgItem(IDC_LVW_Net_Components);
  1610. m_hAdaptersListView = GetDlgItem(IDC_LVW_Bridged_Adapters);
  1611. ::EnableWindow(m_hwndLV, FALSE);
  1612. return CLanNetPage::OnInitDialog(uMsg, wParam, lParam, bHandled);
  1613. }
  1614. LRESULT CLanNetNetworkBridgePage::OnAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1615. {
  1616. TraceFileFunc(ttidLanUi);
  1617. return OnAddHelper(m_hwndLV);
  1618. }
  1619. LRESULT CLanNetNetworkBridgePage::OnRemove(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1620. {
  1621. TraceFileFunc(ttidLanUi);
  1622. return OnRemoveHelper(m_hwndLV);
  1623. }
  1624. LRESULT CLanNetNetworkBridgePage::OnProperties(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1625. {
  1626. TraceFileFunc(ttidLanUi);
  1627. return OnPropertiesHelper(m_hwndLV);
  1628. }
  1629. //+---------------------------------------------------------------------------
  1630. //
  1631. // Member: CLanNetNetworkBridgePage::OnConfigure
  1632. //
  1633. // Purpose: Handles the clicking of the Configure button
  1634. //
  1635. // Arguments:
  1636. // wNotifyCode []
  1637. // wID []
  1638. // hWndCtl []
  1639. // bHandled []
  1640. //
  1641. // Returns:
  1642. //
  1643. // Notes:
  1644. //
  1645. LRESULT CLanNetNetworkBridgePage::OnConfigure(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  1646. BOOL& bHandled)
  1647. {
  1648. TraceFileFunc(ttidLanUi);
  1649. m_fDirty = TRUE;
  1650. HRESULT hr = E_FAIL;
  1651. AssertSz(1 == ListView_GetSelectedCount(m_hAdaptersListView), "No item selected, button should have been disabled"); // should be enforced through enable/disable
  1652. int nSelection = ListView_GetSelectionMark(m_hAdaptersListView);
  1653. if(-1 != nSelection)
  1654. {
  1655. LVITEM ListViewItem = {0};
  1656. ListViewItem.stateMask = -1;
  1657. ListViewItem.mask = LVIF_STATE | LVIF_PARAM | LVIF_IMAGE;
  1658. ListViewItem.iItem = nSelection;
  1659. if(TRUE == ListView_GetItem(m_hAdaptersListView, &ListViewItem))
  1660. {
  1661. // REVIEW this ref should be protected by the apt nature of the wndproc
  1662. INetConnection* pNetConnection = reinterpret_cast<INetConnection*>(ListViewItem.lParam);
  1663. Assert(NULL != pNetConnection);
  1664. INetLanConnection* pNetLanConnection;
  1665. hr = HrQIAndSetProxyBlanket(pNetConnection, &pNetLanConnection);
  1666. if (SUCCEEDED(hr))
  1667. {
  1668. LANCON_INFO linfo;
  1669. hr = pNetLanConnection->GetInfo(LCIF_COMP, &linfo);
  1670. if (SUCCEEDED(hr))
  1671. {
  1672. INetCfgComponent* pNetCfgComponent;
  1673. hr = HrPnccFromGuid(m_pnc, linfo.guid, &pNetCfgComponent); // REVIEW can we use our m_pnc here?
  1674. if(SUCCEEDED(hr))
  1675. {
  1676. BOOL bProceed = TRUE;
  1677. if (m_fDirty)
  1678. {
  1679. bProceed = FALSE;
  1680. LPWSTR szDisplayName;
  1681. NETCON_PROPERTIES *pProps = NULL;
  1682. HRESULT hrT = m_pconn->GetProperties(&pProps);
  1683. if (SUCCEEDED(hrT))
  1684. {
  1685. szDisplayName = pProps->pszwName;
  1686. }
  1687. else
  1688. {
  1689. szDisplayName = const_cast<LPWSTR>(SzLoadIds(IDS_LAN_DEFAULT_CONN_NAME));
  1690. }
  1691. if (IDYES == ::MessageBox(m_hWnd, SzLoadIds(IDS_DIRTY_PROPERTIES), szDisplayName, MB_YESNO))
  1692. {
  1693. bProceed = TRUE;
  1694. }
  1695. if (SUCCEEDED(hrT))
  1696. {
  1697. FreeNetconProperties(pProps);
  1698. }
  1699. }
  1700. if (bProceed)
  1701. {
  1702. hr = RaiseDeviceConfiguration(m_hWnd, pNetCfgComponent);
  1703. PostQuitMessage(0);
  1704. }
  1705. ReleaseObj(pNetCfgComponent);
  1706. }
  1707. // no cleanup required
  1708. }
  1709. ReleaseObj(pNetLanConnection);
  1710. }
  1711. }
  1712. }
  1713. TraceError("CLanNetPage::OnConfigure", hr);
  1714. return LresFromHr(hr);
  1715. }
  1716. LRESULT CLanNetNetworkBridgePage::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  1717. {
  1718. TraceFileFunc(ttidLanUi);
  1719. return OnKillActiveHelper(m_hwndLV);
  1720. }
  1721. LRESULT CLanNetNetworkBridgePage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  1722. {
  1723. TraceFileFunc(ttidLanUi);
  1724. LRESULT lResult = FALSE;
  1725. WCHAR DummyBuffer[255]; // REMOVE
  1726. LVITEM ListViewItem = {0};
  1727. ListViewItem.pszText = DummyBuffer; // REMOVE
  1728. ListViewItem.cchTextMax = 255; // REMOVE
  1729. ListViewItem.stateMask = -1;
  1730. ListViewItem.mask = LVIF_TEXT /* REMOVE */ | LVIF_STATE | LVIF_PARAM | LVIF_IMAGE;
  1731. HRESULT hr;
  1732. IHNetCfgMgr* pHomeNetConfigManager;
  1733. hr = HrCreateInstance(CLSID_HNetCfgMgr, CLSCTX_INPROC, &pHomeNetConfigManager);
  1734. if(SUCCEEDED(hr))
  1735. {
  1736. IHNetConnection* pBridgeHomeNetConnection;
  1737. IHNetBridge* pNetBridge;
  1738. hr = pHomeNetConfigManager->GetIHNetConnectionForINetConnection(m_pconn, &pBridgeHomeNetConnection); // REVIEW lazy eval?
  1739. if(SUCCEEDED(hr))
  1740. {
  1741. hr = pBridgeHomeNetConnection->GetControlInterface(IID_IHNetBridge, reinterpret_cast<void**>(&pNetBridge));
  1742. if(SUCCEEDED(hr))
  1743. {
  1744. int nAdapterCount = ListView_GetItemCount(m_hAdaptersListView); // REVIEW docs list no error code
  1745. while(0 != nAdapterCount)
  1746. {
  1747. nAdapterCount--;
  1748. ListViewItem.iItem = nAdapterCount;
  1749. if(TRUE == ListView_GetItem(m_hAdaptersListView, &ListViewItem))
  1750. {
  1751. NETCON_PROPERTIES* pProperties;
  1752. INetConnection* pNetConnection = reinterpret_cast<INetConnection*>(ListViewItem.lParam);
  1753. int nState = LVIS_STATEIMAGEMASK & ListViewItem.state;
  1754. hr = pNetConnection->GetProperties(&pProperties);
  1755. if(SUCCEEDED(hr))
  1756. {
  1757. // WARNING this code assumes only one bridge allowed
  1758. // see if checkbox matches the current bridge state and update if necessary
  1759. IHNetConnection* pHomeNetConnection;
  1760. if(INDEXTOSTATEIMAGEMASK(SELS_CHECKED) == nState)
  1761. {
  1762. if(!(NCCF_BRIDGED & pProperties->dwCharacter))
  1763. {
  1764. hr = pHomeNetConfigManager->GetIHNetConnectionForINetConnection(pNetConnection, &pHomeNetConnection);
  1765. if(SUCCEEDED(hr))
  1766. {
  1767. IHNetBridgedConnection* pBridgedConnection;
  1768. hr = pNetBridge->AddMember(pHomeNetConnection, &pBridgedConnection, m_pnc); // REVIEW if we fail to add any members, should we destroy the bridge?
  1769. if(SUCCEEDED(hr))
  1770. {
  1771. ReleaseObj(pBridgedConnection);
  1772. }
  1773. ReleaseObj(pHomeNetConnection);
  1774. }
  1775. // no cleanup needed
  1776. }
  1777. // no cleanup needed
  1778. }
  1779. else if(INDEXTOSTATEIMAGEMASK(SELS_UNCHECKED) == nState)
  1780. {
  1781. if(NCCF_BRIDGED & pProperties->dwCharacter)
  1782. {
  1783. hr = pHomeNetConfigManager->GetIHNetConnectionForINetConnection(pNetConnection, &pHomeNetConnection);
  1784. if(SUCCEEDED(hr))
  1785. {
  1786. IHNetBridgedConnection* pBridgedConnection;
  1787. hr = pHomeNetConnection->GetControlInterface(IID_IHNetBridgedConnection, reinterpret_cast<void**>(&pBridgedConnection));
  1788. if(SUCCEEDED(hr))
  1789. {
  1790. pBridgedConnection->RemoveFromBridge(m_pnc);
  1791. }
  1792. ReleaseObj(pHomeNetConnection);
  1793. }
  1794. //no cleanup needed
  1795. }
  1796. // no cleanup needed
  1797. }
  1798. else
  1799. {
  1800. AssertSz(FALSE, "Bad state");
  1801. }
  1802. FreeNetconProperties(pProperties);
  1803. }
  1804. // no cleanup needed
  1805. }
  1806. else
  1807. {
  1808. hr = E_FAIL; // error code coversion
  1809. }
  1810. //no cleanup needed
  1811. }
  1812. ReleaseObj(pNetBridge);
  1813. }
  1814. ReleaseObj(pBridgeHomeNetConnection);
  1815. }
  1816. ReleaseObj(pHomeNetConfigManager);
  1817. }
  1818. else
  1819. {
  1820. hr = S_OK; // fail silently in this case
  1821. }
  1822. if(SUCCEEDED(hr))
  1823. {
  1824. if( PSNRET_NOERROR != CLanNetPage::OnApply(idCtrl, pnmh, bHandled) )
  1825. {
  1826. hr = E_FAIL;
  1827. }
  1828. else
  1829. {
  1830. //
  1831. // Since we have done bridge binding operations inside an existing NetCfg context
  1832. // (m_pnc), it is our responsibility to refresh netshell. Fire a refresh-all.
  1833. //
  1834. INetConnectionRefresh *pNetConRefresh;
  1835. hr = CoCreateInstance(
  1836. CLSID_ConnectionManager,
  1837. NULL,
  1838. CLSCTX_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  1839. IID_INetConnectionRefresh, reinterpret_cast<void **>(&pNetConRefresh)
  1840. );
  1841. if( SUCCEEDED(hr) )
  1842. {
  1843. pNetConRefresh->RefreshAll();
  1844. pNetConRefresh->Release();
  1845. }
  1846. }
  1847. }
  1848. m_fDirty = FALSE;
  1849. lResult = LresFromHr(hr);
  1850. return lResult;
  1851. }
  1852. LRESULT CLanNetNetworkBridgePage::OnDeleteItem(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  1853. {
  1854. TraceFileFunc(ttidLanUi);
  1855. NM_LISTVIEW * pnmlv = reinterpret_cast<NM_LISTVIEW *>(pnmh);
  1856. if(IDC_LVW_Net_Components == idCtrl)
  1857. {
  1858. LvDeleteItem(m_hwndLV, pnmlv->iItem);
  1859. }
  1860. else
  1861. {
  1862. Assert(IDC_LVW_Bridged_Adapters == idCtrl);
  1863. Assert(NULL != pnmlv->lParam);
  1864. ReleaseObj(reinterpret_cast<INetConnection*>(pnmlv->lParam));
  1865. }
  1866. m_fDirty = TRUE;
  1867. return 0;
  1868. }
  1869. LRESULT CLanNetNetworkBridgePage::OnClick(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  1870. {
  1871. TraceFileFunc(ttidLanUi);
  1872. m_fDirty = TRUE;
  1873. if(IDC_LVW_Net_Components == idCtrl)
  1874. {
  1875. OnListClick(m_hwndLV, m_hWnd, m_pnc, m_punk,
  1876. m_pnccAdapter, &m_listBindingPaths, FALSE, m_fReadOnly);
  1877. }
  1878. else
  1879. {
  1880. Assert(idCtrl == IDC_LVW_Bridged_Adapters);
  1881. if(FALSE == m_fReadOnly)
  1882. {
  1883. DWORD dwpts = GetMessagePos();
  1884. LV_HITTESTINFO lvhti;
  1885. lvhti.pt.x = LOWORD( dwpts );
  1886. lvhti.pt.y = HIWORD( dwpts );
  1887. ::MapWindowPoints(NULL , m_hAdaptersListView , (LPPOINT) &(lvhti.pt) , 1);
  1888. int iItem = ListView_HitTest( m_hAdaptersListView, &lvhti );
  1889. if (-1 != iItem && LVHT_ONITEMSTATEICON & lvhti.flags)
  1890. {
  1891. LV_ITEM lvItem;
  1892. lvItem.iItem = iItem;
  1893. lvItem.iSubItem = 0;
  1894. lvItem.mask = LVIF_STATE;
  1895. lvItem.stateMask = LVIS_STATEIMAGEMASK;
  1896. if(ListView_GetItem(m_hAdaptersListView, &lvItem))
  1897. {
  1898. if(INDEXTOSTATEIMAGEMASK(SELS_CHECKED) == lvItem.state)
  1899. {
  1900. lvItem.state = INDEXTOSTATEIMAGEMASK(SELS_UNCHECKED);
  1901. }
  1902. else
  1903. {
  1904. lvItem.state = INDEXTOSTATEIMAGEMASK(SELS_CHECKED);
  1905. }
  1906. ListView_SetItem(m_hAdaptersListView, &lvItem);
  1907. }
  1908. }
  1909. }
  1910. HWND hConfigureButton = GetDlgItem(IDC_PSB_Configure);
  1911. Assert(NULL != hConfigureButton);
  1912. ::EnableWindow(hConfigureButton, ListView_GetSelectedCount(m_hAdaptersListView) ? TRUE : FALSE);
  1913. }
  1914. return 0;
  1915. }
  1916. LRESULT CLanNetNetworkBridgePage::OnDbClick(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  1917. {
  1918. TraceFileFunc(ttidLanUi);
  1919. if(IDC_LVW_Net_Components == idCtrl)
  1920. {
  1921. OnListClick(m_hwndLV, m_hWnd, m_pnc, m_punk,
  1922. m_pnccAdapter, &m_listBindingPaths, TRUE, m_fReadOnly);
  1923. }
  1924. m_fDirty = TRUE;
  1925. return 0;
  1926. }
  1927. LRESULT CLanNetNetworkBridgePage::OnKeyDown(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  1928. {
  1929. TraceFileFunc(ttidLanUi);
  1930. if (!m_fReadOnly)
  1931. {
  1932. LV_KEYDOWN* plvkd = (LV_KEYDOWN*)pnmh;
  1933. if(IDC_LVW_Net_Components == idCtrl)
  1934. {
  1935. OnListKeyDown(m_hwndLV, &m_listBindingPaths, plvkd->wVKey);
  1936. }
  1937. else
  1938. {
  1939. Assert(IDC_LVW_Bridged_Adapters == idCtrl);
  1940. if ((VK_SPACE == plvkd->wVKey) && (GetAsyncKeyState(VK_MENU)>=0))
  1941. {
  1942. int iItem = ListView_GetSelectionMark(m_hAdaptersListView);
  1943. if(-1 != iItem)
  1944. {
  1945. LV_ITEM lvItem;
  1946. lvItem.iItem = iItem;
  1947. lvItem.iSubItem = 0;
  1948. lvItem.mask = LVIF_STATE;
  1949. lvItem.stateMask = LVIS_STATEIMAGEMASK;
  1950. if(ListView_GetItem(m_hAdaptersListView, &lvItem))
  1951. {
  1952. if(INDEXTOSTATEIMAGEMASK(SELS_CHECKED) == lvItem.state)
  1953. {
  1954. lvItem.state = INDEXTOSTATEIMAGEMASK(SELS_UNCHECKED);
  1955. }
  1956. else
  1957. {
  1958. lvItem.state = INDEXTOSTATEIMAGEMASK(SELS_CHECKED);
  1959. }
  1960. ListView_SetItem(m_hAdaptersListView, &lvItem);
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. return 0;
  1967. }
  1968. LRESULT CLanNetNetworkBridgePage::OnItemChanged(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  1969. {
  1970. TraceFileFunc(ttidLanUi);
  1971. NM_LISTVIEW * pnmlv = reinterpret_cast<NM_LISTVIEW *>(pnmh);
  1972. Assert(pnmlv);
  1973. // Reset the buttons and the description text based on the changed selection
  1974. if(IDC_LVW_Net_Components == idCtrl)
  1975. {
  1976. LvSetButtons(m_hWnd, m_handles, m_fReadOnly, m_punk);
  1977. }
  1978. return 0;
  1979. }
  1980. HRESULT CLanNetNetworkBridgePage::InitializeExtendedUI()
  1981. {
  1982. TraceFileFunc(ttidLanUi);
  1983. HRESULT hResult = HrInitListView(m_hwndLV, m_pnc, m_pnccAdapter,
  1984. &m_listBindingPaths,
  1985. &m_hilCheckIcons);
  1986. // Reset the buttons and the description text based on the changed selection
  1987. LvSetButtons(m_hWnd, m_handles, m_fReadOnly, m_punk);
  1988. Assert(NULL != m_hAdaptersListView);
  1989. SP_CLASSIMAGELIST_DATA* pcild = reinterpret_cast<SP_CLASSIMAGELIST_DATA *>(::GetWindowLongPtr(::GetParent(m_hAdaptersListView), GWLP_USERDATA));
  1990. Assert(NULL != pcild);
  1991. HrInitCheckboxListView(m_hAdaptersListView, &m_hAdaptersListImageList, pcild);
  1992. hResult = FillListViewWithConnections(m_hAdaptersListView);
  1993. return hResult;
  1994. }
  1995. HRESULT CLanNetNetworkBridgePage::UninitializeExtendedUI()
  1996. {
  1997. TraceFileFunc(ttidLanUi);
  1998. UninitListView(m_hwndLV);
  1999. ListView_DeleteAllItems(m_hAdaptersListView);
  2000. ImageList_Destroy(m_hAdaptersListImageList);
  2001. return S_OK;
  2002. }
  2003. HRESULT CLanNetNetworkBridgePage::FillListViewWithConnections(HWND hListView)
  2004. {
  2005. TraceFileFunc(ttidLanUi);
  2006. HRESULT hResult;
  2007. INetConnectionManager* pLanConnectionManager;
  2008. hResult = HrCreateInstance(CLSID_LanConnectionManager, CLSCTX_SERVER | CLSCTX_NO_CODE_DOWNLOAD, &pLanConnectionManager);
  2009. if (SUCCEEDED(hResult))
  2010. {
  2011. CIterNetCon NetConnectionIterator(pLanConnectionManager, NCME_DEFAULT);
  2012. INetConnection* pConnection;
  2013. int i = 0;
  2014. while (S_OK == NetConnectionIterator.HrNext(&pConnection))
  2015. {
  2016. NcSetProxyBlanket(pConnection);
  2017. NETCON_PROPERTIES* pProperties;
  2018. hResult = pConnection->GetProperties(&pProperties);
  2019. if(SUCCEEDED(hResult))
  2020. {
  2021. if(NCM_LAN == pProperties->MediaType) // we only bridge lan connections
  2022. {
  2023. if(0 == ((NCCF_FIREWALLED | NCCF_SHARED) & pProperties->dwCharacter))
  2024. {
  2025. SP_CLASSIMAGELIST_DATA * pcild;
  2026. INT nIndex = 0;
  2027. pcild = reinterpret_cast<SP_CLASSIMAGELIST_DATA *>(::GetWindowLongPtr(::GetParent(m_hAdaptersListView), GWLP_USERDATA));
  2028. Assert(pcild);
  2029. (VOID) HrSetupDiGetClassImageIndex(pcild, &GUID_DEVCLASS_NETCLIENT, &nIndex);
  2030. LV_ITEM lvi = {0};
  2031. lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_PARAM | LVIF_IMAGE;
  2032. lvi.state = LVIS_SELECTED | LVIS_FOCUSED;
  2033. // WARNING assuming only one bridge
  2034. lvi.state |= INDEXTOSTATEIMAGEMASK(pProperties->dwCharacter & NCCF_BRIDGED ? SELS_CHECKED : SELS_UNCHECKED);
  2035. lvi.iImage = nIndex;
  2036. lvi.pszText = pProperties->pszwName;
  2037. lvi.cchTextMax = lstrlen(pProperties->pszwName);
  2038. lvi.lParam = reinterpret_cast<LPARAM>(pConnection);
  2039. lvi.iItem = i++;
  2040. ListView_InsertItem(hListView, &lvi);
  2041. }
  2042. }
  2043. FreeNetconProperties(pProperties);
  2044. }
  2045. //Released by WM_DELETEITEM
  2046. }
  2047. ReleaseObj(pLanConnectionManager);
  2048. }
  2049. return hResult;
  2050. }
  2051. //
  2052. // CLanAdvancedPage
  2053. //
  2054. //+---------------------------------------------------------------------------
  2055. //
  2056. // Function: HrQueryLanAdvancedPage
  2057. //
  2058. // Purpose: Determines whether the 'Shared Access' page should be shown,
  2059. // and if so supplies an initialized object for the page.
  2060. // The page is displayed if
  2061. // (a) the user is an admin or power-user, and
  2062. // (b) TCP/IP is installed, and
  2063. // (i) this is already a shared connection, or
  2064. // (ii) there is at least one other LAN connection.
  2065. //
  2066. // Arguments:
  2067. // pconn [in] the connection for which a page is requested
  2068. // pspAdvanced[out] the created page, if appropriate
  2069. //
  2070. // Returns: S_OK if success, Win32 error otherwise
  2071. //
  2072. // Author: aboladeg 22 Aug 1998
  2073. //
  2074. // Notes:
  2075. //
  2076. HRESULT HrQueryLanAdvancedPage(INetConnection* pconn, IUnknown* punk,
  2077. CPropSheetPage*& pspAdvanced, IHNetCfgMgr *pHNetCfgMgr,
  2078. IHNetIcsSettings *pHNetIcsSettings,
  2079. IHNetConnection *pHNetConn)
  2080. {
  2081. HRESULT hr = S_OK;
  2082. TraceFileFunc(ttidLanUi);
  2083. pspAdvanced = NULL;
  2084. BOOL fShared = FALSE;
  2085. BOOL fAnyShared = FALSE;
  2086. HNET_CONN_PROPERTIES *pHNetProps;
  2087. IHNetConnection **rgPrivateCons;
  2088. ULONG cPrivate;
  2089. LONG lxCurrentPrivate;
  2090. //
  2091. // (i) Determine if this connection is currently shared
  2092. //
  2093. hr = pHNetConn->GetProperties(&pHNetProps);
  2094. if (FAILED(hr))
  2095. {
  2096. return hr;
  2097. }
  2098. if(FALSE == pHNetProps->fPartOfBridge && FALSE == pHNetProps->fBridge) // no sharing a bridged adapter or the bridge
  2099. {
  2100. fShared = pHNetProps->fIcsPublic;
  2101. // (ii) Determine what connections could serve as a private connection
  2102. // if pconn were made the public connection
  2103. //
  2104. hr = pHNetIcsSettings->GetPossiblePrivateConnections(
  2105. pHNetConn,
  2106. &cPrivate,
  2107. &rgPrivateCons,
  2108. &lxCurrentPrivate
  2109. );
  2110. if (SUCCEEDED(hr))
  2111. {
  2112. pspAdvanced = new CLanAdvancedPage(punk, pconn, fShared, pHNetProps->fIcsPrivate, pHNetProps->fFirewalled, rgPrivateCons,
  2113. cPrivate, lxCurrentPrivate,
  2114. g_aHelpIDs_IDD_LAN_ADVANCED,
  2115. pHNetConn, pHNetCfgMgr, pHNetIcsSettings);
  2116. }
  2117. }
  2118. CoTaskMemFree(pHNetProps);
  2119. return S_OK;
  2120. }
  2121. CLanAdvancedPage::CLanAdvancedPage(IUnknown *punk, INetConnection *pconn,
  2122. BOOL fShared, BOOL fICSPrivate, BOOL fFirewalled, IHNetConnection **rgPrivateCons,
  2123. ULONG cPrivate, LONG lxCurrentPrivate,
  2124. const DWORD * adwHelpIDs, IHNetConnection *pHNConn,
  2125. IHNetCfgMgr *pHNetCfgMgr, IHNetIcsSettings *pHNetIcsSettings)
  2126. {
  2127. TraceFileFunc(ttidLanUi);
  2128. m_pconn = pconn;
  2129. m_punk = punk;
  2130. m_fShared = fShared;
  2131. m_fICSPrivate = fICSPrivate;
  2132. m_fFirewalled = fFirewalled;
  2133. m_fOtherShared = FALSE;
  2134. m_pOldSharedConnection = NULL;
  2135. m_fResetPrivateAdapter = fShared && -1 == lxCurrentPrivate;
  2136. m_rgPrivateCons = rgPrivateCons;
  2137. m_cPrivate = cPrivate;
  2138. m_lxCurrentPrivate = lxCurrentPrivate;
  2139. m_adwHelpIDs = adwHelpIDs;
  2140. m_pHNetCfgMgr = pHNetCfgMgr;
  2141. AddRefObj(m_pHNetCfgMgr);
  2142. m_pHNetIcsSettings = pHNetIcsSettings;
  2143. AddRefObj(m_pHNetIcsSettings);
  2144. m_pHNetConn = pHNConn;
  2145. AddRefObj(m_pHNetConn);
  2146. LinkWindow_RegisterClass(); // REVIEW failure here?
  2147. }
  2148. CLanAdvancedPage::~CLanAdvancedPage()
  2149. {
  2150. TraceFileFunc(ttidLanUi);
  2151. if (m_rgPrivateCons)
  2152. {
  2153. for (ULONG i = 0; i < m_cPrivate; i++)
  2154. {
  2155. ReleaseObj(m_rgPrivateCons[i]);
  2156. }
  2157. CoTaskMemFree(m_rgPrivateCons);
  2158. }
  2159. ReleaseObj(m_pHNetCfgMgr);
  2160. ReleaseObj(m_pHNetIcsSettings);
  2161. ReleaseObj(m_pHNetConn);
  2162. ReleaseObj(m_pOldSharedConnection);
  2163. LinkWindow_UnregisterClass(_Module.GetResourceInstance());
  2164. }
  2165. // util function used below
  2166. static BOOL IsConnectionIncomingOnly (INetConnection * pNC)
  2167. {
  2168. // Kludge Alert!!!!
  2169. // this #@$% camera doesn't have the right characteristics,
  2170. // so I'm checking by device name
  2171. BOOL b = FALSE;
  2172. DWORD dwCharacteristics = 0;
  2173. NETCON_PROPERTIES * pProps = NULL;
  2174. HRESULT hr = pNC->GetProperties (&pProps);
  2175. if (pProps) {
  2176. dwCharacteristics = pProps->dwCharacter;
  2177. if (!wcscmp (pProps->pszwDeviceName, L"Microsoft TV/Video Connection"))
  2178. b = TRUE;
  2179. NcFreeNetconProperties (pProps);
  2180. }
  2181. if (b)
  2182. return TRUE;
  2183. return (dwCharacteristics & NCCF_INCOMING_ONLY) ? TRUE : FALSE;
  2184. }
  2185. //+---------------------------------------------------------------------------
  2186. //
  2187. // Member: CLanAdvancedPage::OnInitDialog
  2188. //
  2189. // Purpose: Handles the WM_INITDIALOG message
  2190. //
  2191. // Arguments:
  2192. // uMsg []
  2193. // wParam []
  2194. // lParam []
  2195. // bHandled []
  2196. //
  2197. // Returns: TRUE
  2198. //
  2199. // Author: aboladeg 14 May 1998
  2200. //
  2201. // Notes:
  2202. //
  2203. LRESULT CLanAdvancedPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  2204. LPARAM lParam, BOOL& bHandled)
  2205. {
  2206. TraceFileFunc(ttidLanUi);
  2207. LPWSTR pszw;
  2208. HRESULT hr;
  2209. // init firewall section
  2210. if ( IsHNetAllowed(NCPERM_PersonalFirewallConfig) && FALSE == m_fICSPrivate )
  2211. {
  2212. CheckDlgButton(IDC_CHK_Firewall, m_fFirewalled);
  2213. m_fShowDisableFirewallWarning = TRUE; // TODO check registry
  2214. HKEY hFirewallKey;
  2215. if(SUCCEEDED(HrRegOpenKeyEx(HKEY_CURRENT_USER, g_pszFirewallRegKey, KEY_QUERY_VALUE, &hFirewallKey)))
  2216. {
  2217. DWORD dwValue;
  2218. DWORD dwType;
  2219. DWORD dwSize = sizeof(dwValue);
  2220. if(ERROR_SUCCESS == RegQueryValueEx(hFirewallKey, g_pszDisableFirewallWarningValue, NULL, &dwType, reinterpret_cast<BYTE*>(&dwValue), &dwSize))
  2221. {
  2222. if(REG_DWORD == dwType && TRUE == dwValue)
  2223. {
  2224. m_fShowDisableFirewallWarning = FALSE;
  2225. }
  2226. }
  2227. RegCloseKey(hFirewallKey);
  2228. }
  2229. }
  2230. else
  2231. {
  2232. ::EnableWindow(GetDlgItem(IDC_CHK_Firewall), FALSE);
  2233. }
  2234. // The appearance of the dialog depends on how many LAN connections
  2235. // we have other than the current one. If we have only one,
  2236. // then we just show a checkbox. Otherwise, we display
  2237. // (a) a drop-list of LAN connections if 'm_pconn' is not shared, or
  2238. // (b) a disabled edit-box showing the private LAN connection
  2239. // if 'm_pconn' is shared.
  2240. //
  2241. BOOL fPolicyAllowsSharing = IsHNetAllowed(NCPERM_ShowSharedAccessUi);
  2242. if (m_cPrivate == 0)
  2243. {
  2244. // if the have no private adapters, hide all ICS stuff
  2245. ::ShowWindow(GetDlgItem(IDC_GB_Shared), SW_HIDE);
  2246. ::ShowWindow(GetDlgItem(IDC_CHK_Shared), SW_HIDE);
  2247. ::ShowWindow(GetDlgItem(IDC_CHK_BeaconControl), SW_HIDE);
  2248. ::ShowWindow(GetDlgItem(IDC_ST_ICSLINK), SW_HIDE);
  2249. }
  2250. else if (IsConnectionIncomingOnly (m_pconn)) {
  2251. // bug 281820: disable group box if NCCF_INCOMING_ONLY bit is set
  2252. m_fShared = FALSE;
  2253. ::EnableWindow(GetDlgItem(IDC_GB_Shared), FALSE);
  2254. ::ShowWindow (GetDlgItem(IDC_GB_Shared), SW_HIDE);
  2255. ::EnableWindow(GetDlgItem(IDC_CHK_Shared), FALSE);
  2256. ::ShowWindow (GetDlgItem(IDC_CHK_Shared), SW_HIDE);
  2257. ::EnableWindow(GetDlgItem(IDC_CHK_BeaconControl), FALSE);
  2258. ::ShowWindow (GetDlgItem(IDC_CHK_BeaconControl), SW_HIDE);
  2259. ::EnableWindow(GetDlgItem(IDC_ST_ICSLINK), FALSE);
  2260. ::ShowWindow (GetDlgItem(IDC_ST_ICSLINK), SW_HIDE);
  2261. }
  2262. else if(FALSE == fPolicyAllowsSharing)
  2263. {
  2264. // if policy disables ICS just gray the checkbox
  2265. ::EnableWindow(GetDlgItem(IDC_CHK_Shared), FALSE);
  2266. ::EnableWindow(GetDlgItem(IDC_CHK_BeaconControl), FALSE);
  2267. }
  2268. else if(m_cPrivate > 1)
  2269. {
  2270. // Show a drop-list of LAN connections or a disabled edit-box
  2271. // depending on whether 'm_pconn' is shared, in both cases
  2272. // hiding the smaller groupbox and showing the larger one
  2273. // along with the 'private LAN' label.
  2274. //
  2275. ::ShowWindow(GetDlgItem(IDC_GB_Shared), SW_HIDE);
  2276. ::ShowWindow(GetDlgItem(IDC_GB_PrivateLan), SW_SHOW);
  2277. // show the text label
  2278. ::ShowWindow(GetDlgItem(IDC_ST_HomeNetworkLabel), SW_SHOW);
  2279. ::EnableWindow(GetDlgItem(IDC_ST_HomeNetworkLabel), TRUE);
  2280. // move the beaconcontrol checkbox down
  2281. RECT SourceRect;
  2282. RECT TargetRect;
  2283. ::GetWindowRect(GetDlgItem(IDC_CHK_BeaconControl), &SourceRect);
  2284. ::GetWindowRect(GetDlgItem(IDC_ST_PositionBar), &TargetRect);
  2285. LONG lDelta = TargetRect.top - SourceRect.top; // how far we need to move the controls down
  2286. ::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&SourceRect, 2); // convert screen to client
  2287. ::SetWindowPos( GetDlgItem(IDC_CHK_BeaconControl), NULL, SourceRect.left, SourceRect.top + lDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
  2288. ::GetWindowRect(GetDlgItem(IDC_ST_ICSLINK), &SourceRect);
  2289. ::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&SourceRect, 2); // convert screen to client
  2290. ::SetWindowPos(GetDlgItem(IDC_ST_ICSLINK), NULL, SourceRect.left, SourceRect.top + lDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
  2291. if (m_fShared && !m_fResetPrivateAdapter)
  2292. {
  2293. ::ShowWindow(GetDlgItem(IDC_EDT_PrivateLan), SW_SHOW);
  2294. // Display the private LAN in the editbox
  2295. //
  2296. hr = m_rgPrivateCons[m_lxCurrentPrivate]->GetName(&pszw);
  2297. if (SUCCEEDED(hr))
  2298. {
  2299. SetDlgItemText(IDC_EDT_PrivateLan, pszw);
  2300. CoTaskMemFree(pszw);
  2301. }
  2302. }
  2303. else
  2304. {
  2305. // show and configure the dropdown
  2306. HWND hwndCb = GetDlgItem(IDC_CB_PrivateLan);
  2307. INT i, item;
  2308. ::ShowWindow(hwndCb, SW_SHOW);
  2309. // Add the bogus entry to the combobox
  2310. pszw = const_cast<LPWSTR>(SzLoadIds(IDS_SHAREDACCESS_SELECTADAPTER));
  2311. Assert(pszw);
  2312. item = ComboBox_AddString(hwndCb, pszw);
  2313. if (item != CB_ERR && item != CB_ERRSPACE)
  2314. {
  2315. ComboBox_SetItemData(hwndCb, item, NULL); // ensure item data is null for validation purposes
  2316. }
  2317. // Fill the combobox with LAN names
  2318. //
  2319. for (i = 0; i < (INT)m_cPrivate; i++)
  2320. {
  2321. hr = m_rgPrivateCons[i]->GetName(&pszw);
  2322. if (SUCCEEDED(hr))
  2323. {
  2324. item = ComboBox_AddString(hwndCb, pszw);
  2325. if (item != CB_ERR && item != CB_ERRSPACE)
  2326. {
  2327. ComboBox_SetItemData(
  2328. hwndCb, item, m_rgPrivateCons[i] );
  2329. }
  2330. CoTaskMemFree(pszw);
  2331. }
  2332. }
  2333. ComboBox_SetCurSel( hwndCb, 0 );
  2334. }
  2335. }
  2336. ::EnableWindow(GetDlgItem(IDC_PSB_Settings), m_fShared || m_fFirewalled);
  2337. BOOL fBeaconControl = TRUE;
  2338. HKEY hKey;
  2339. DWORD dwError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGKEY_SHAREDACCESSCLIENTKEYPATH, 0, KEY_QUERY_VALUE, &hKey);
  2340. if(ERROR_SUCCESS == dwError) // if this fails we assume it is on, set the box, and commit on apply
  2341. {
  2342. DWORD dwType;
  2343. DWORD dwData = 0;
  2344. DWORD dwSize = sizeof(dwData);
  2345. dwError = RegQueryValueEx(hKey, REGVAL_SHAREDACCESSCLIENTENABLECONTROL, 0, &dwType, reinterpret_cast<LPBYTE>(&dwData), &dwSize);
  2346. if(ERROR_SUCCESS == dwError && REG_DWORD == dwType && 0 == dwData)
  2347. {
  2348. fBeaconControl = FALSE;
  2349. }
  2350. RegCloseKey(hKey);
  2351. }
  2352. CheckDlgButton(IDC_CHK_Shared, m_fShared);
  2353. CheckDlgButton(IDC_CHK_BeaconControl, fBeaconControl);
  2354. ::EnableWindow(GetDlgItem(IDC_CHK_BeaconControl), m_fShared && fPolicyAllowsSharing);
  2355. //if the machine is personal or workstation, show the HNW link
  2356. OSVERSIONINFOEXW verInfo = {0};
  2357. ULONGLONG ConditionMask = 0;
  2358. verInfo.dwOSVersionInfoSize = sizeof(verInfo);
  2359. verInfo.wProductType = VER_NT_WORKSTATION;
  2360. VER_SET_CONDITION(ConditionMask, VER_PRODUCT_TYPE, VER_LESS_EQUAL);
  2361. if(0 != VerifyVersionInfo(&verInfo, VER_PRODUCT_TYPE, ConditionMask))
  2362. {
  2363. // but only if not on a domain
  2364. LPWSTR pszNameBuffer;
  2365. NETSETUP_JOIN_STATUS BufferType;
  2366. if(NERR_Success == NetGetJoinInformation(NULL, &pszNameBuffer, &BufferType))
  2367. {
  2368. NetApiBufferFree(pszNameBuffer);
  2369. if(NetSetupDomainName != BufferType)
  2370. {
  2371. ::ShowWindow(GetDlgItem(IDC_ST_HNWLINK), SW_SHOW);
  2372. }
  2373. }
  2374. }
  2375. return TRUE;
  2376. }
  2377. //+---------------------------------------------------------------------------
  2378. //
  2379. // Member: CLanAdvancedPage::OnContextMenu
  2380. //
  2381. // Purpose: When right click a control, bring up help
  2382. //
  2383. // Arguments: Standard command parameters
  2384. //
  2385. // Returns: Standard return
  2386. //
  2387. LRESULT
  2388. CLanAdvancedPage::OnContextMenu(UINT uMsg,
  2389. WPARAM wParam,
  2390. LPARAM lParam,
  2391. BOOL& fHandled)
  2392. {
  2393. TraceFileFunc(ttidLanUi);
  2394. if (m_adwHelpIDs != NULL)
  2395. {
  2396. ::WinHelp(m_hWnd,
  2397. c_szNetCfgHelpFile,
  2398. HELP_CONTEXTMENU,
  2399. (ULONG_PTR)m_adwHelpIDs);
  2400. }
  2401. return 0;
  2402. }
  2403. //+---------------------------------------------------------------------------
  2404. //
  2405. // Member: CLanAdvancedPage::OnHelp
  2406. //
  2407. // Purpose: When drag context help icon over a control, bring up help
  2408. //
  2409. // Arguments: Standard command parameters
  2410. //
  2411. // Returns: Standard return
  2412. //
  2413. LRESULT
  2414. CLanAdvancedPage::OnHelp(UINT uMsg,
  2415. WPARAM wParam,
  2416. LPARAM lParam,
  2417. BOOL& fHandled)
  2418. {
  2419. TraceFileFunc(ttidLanUi);
  2420. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  2421. Assert(lphi);
  2422. if ((m_adwHelpIDs != NULL) && (HELPINFO_WINDOW == lphi->iContextType))
  2423. {
  2424. ::WinHelp(static_cast<HWND>(lphi->hItemHandle),
  2425. c_szNetCfgHelpFile,
  2426. HELP_WM_HELP,
  2427. (ULONG_PTR)m_adwHelpIDs);
  2428. }
  2429. return 0;
  2430. }
  2431. //+---------------------------------------------------------------------------
  2432. //
  2433. // Member: CLanAdvancedPage::OnApply
  2434. //
  2435. // Purpose: Called when the 'Shared Access' page is applied
  2436. //
  2437. // Arguments:
  2438. // idCtrl []
  2439. // pnmh []
  2440. // bHandled []
  2441. //
  2442. // Returns:
  2443. //
  2444. // Author: aboladeg 14 May 1998
  2445. //
  2446. // Notes:
  2447. //
  2448. LRESULT CLanAdvancedPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  2449. {
  2450. TraceFileFunc(ttidLanUi);
  2451. HRESULT hr = S_OK;
  2452. IHNetIcsPrivateConnection *pIcsPrivate;
  2453. IHNetConnection *pPrivateConn;
  2454. IHNetIcsPublicConnection *pIcsPublic;
  2455. ULONG ulcPub, ulcPvt;
  2456. BOOLEAN fPrivateConfigured = FALSE;
  2457. BOOLEAN fConflictDialogDisplayed = FALSE;
  2458. HNET_CONN_PROPERTIES *pProps;
  2459. if (!!m_fFirewalled != !!IsDlgButtonChecked(IDC_CHK_Firewall))
  2460. {
  2461. IHNetFirewalledConnection *pFWConn;
  2462. if (m_fFirewalled)
  2463. {
  2464. //
  2465. // Obtain our firewalled connection interface
  2466. //
  2467. hr = m_pHNetConn->GetControlInterface(
  2468. __uuidof(IHNetFirewalledConnection),
  2469. reinterpret_cast<void**>(&pFWConn)
  2470. );
  2471. if (SUCCEEDED(hr))
  2472. {
  2473. hr = pFWConn->Unfirewall();
  2474. ReleaseObj(pFWConn);
  2475. if (SUCCEEDED(hr))
  2476. {
  2477. m_fFirewalled = FALSE;
  2478. }
  2479. }
  2480. }
  2481. else
  2482. {
  2483. hr = m_pHNetConn->Firewall(&pFWConn);
  2484. if (SUCCEEDED(hr))
  2485. {
  2486. ReleaseObj(pFWConn);
  2487. m_fFirewalled = TRUE;
  2488. }
  2489. }
  2490. if (!SUCCEEDED(hr))
  2491. {
  2492. if (HRESULT_CODE(hr) == ERROR_SHARING_RRAS_CONFLICT)
  2493. {
  2494. fConflictDialogDisplayed = TRUE;
  2495. NcMsgBox(_Module.GetResourceInstance(),
  2496. m_hWnd,
  2497. IDS_LAN_CAPTION,
  2498. IDS_LANUI_SHARING_CONFLICT,
  2499. MB_ICONINFORMATION | MB_OK);
  2500. }
  2501. else
  2502. {
  2503. NcRasMsgBoxWithErrorText (HRESULT_CODE(hr),
  2504. _Module.GetResourceInstance(), m_hWnd,
  2505. IDS_LANUI_ERROR_CAPTION, IDS_TEXT_WITH_RAS_ERROR,
  2506. m_fFirewalled ? IDS_LAN_UNSHARE_FAILED : IDS_LAN_SHARE_FAILED,
  2507. MB_OK | MB_ICONEXCLAMATION );
  2508. }
  2509. }
  2510. }
  2511. if (!!m_fShared != !!IsDlgButtonChecked(IDC_CHK_Shared))
  2512. {
  2513. if (m_fShared)
  2514. {
  2515. //
  2516. // Instead of dealing w/ the public and private connection
  2517. // individually, we simply just diasable all sharing
  2518. //
  2519. hr = m_pHNetIcsSettings->DisableIcs(&ulcPub, &ulcPvt);
  2520. if (SUCCEEDED(hr))
  2521. {
  2522. m_fShared = FALSE;
  2523. }
  2524. }
  2525. else
  2526. {
  2527. if (m_cPrivate > 1)
  2528. {
  2529. HWND hWndCb = GetDlgItem(IDC_CB_PrivateLan);
  2530. INT item = ComboBox_GetCurSel(hWndCb);
  2531. if (item != CB_ERR)
  2532. {
  2533. pPrivateConn =
  2534. (IHNetConnection*)ComboBox_GetItemData(hWndCb, item);
  2535. }
  2536. }
  2537. else
  2538. {
  2539. ASSERT(NULL != m_rgPrivateCons);
  2540. pPrivateConn = m_rgPrivateCons[0];
  2541. }
  2542. //
  2543. // Check to see if the selected private connection is already
  2544. // configured as such.
  2545. //
  2546. if (SUCCEEDED(pPrivateConn->GetProperties(&pProps)))
  2547. {
  2548. fPrivateConfigured = pProps->fIcsPrivate;
  2549. CoTaskMemFree(pProps);
  2550. }
  2551. if (m_fOtherShared)
  2552. {
  2553. if (fPrivateConfigured)
  2554. {
  2555. //
  2556. // Unshare old public connection only. Leaving the
  2557. // private connection as-is prevents a lot of
  2558. // useless work.
  2559. //
  2560. ASSERT(NULL != m_pOldSharedConnection);
  2561. hr = m_pOldSharedConnection->Unshare();
  2562. }
  2563. else
  2564. {
  2565. //
  2566. // We need to configure a new private connection, so
  2567. // just wipe out the old configuration.
  2568. //
  2569. hr = m_pHNetIcsSettings->DisableIcs(&ulcPub, &ulcPvt);
  2570. }
  2571. }
  2572. if (SUCCEEDED(hr))
  2573. {
  2574. hr = m_pHNetConn->SharePublic(&pIcsPublic);
  2575. if (SUCCEEDED(hr))
  2576. {
  2577. if (!fPrivateConfigured)
  2578. {
  2579. hr = pPrivateConn->SharePrivate(&pIcsPrivate);
  2580. if (SUCCEEDED(hr))
  2581. {
  2582. ReleaseObj(pIcsPrivate);
  2583. m_fShared = TRUE;
  2584. }
  2585. else
  2586. {
  2587. pIcsPublic->Unshare();
  2588. }
  2589. }
  2590. else
  2591. {
  2592. m_fShared = TRUE;
  2593. }
  2594. ReleaseObj(pIcsPublic);
  2595. }
  2596. }
  2597. }
  2598. if (!SUCCEEDED(hr))
  2599. {
  2600. if (HRESULT_CODE(hr) == ERROR_SHARING_RRAS_CONFLICT)
  2601. {
  2602. if (!fConflictDialogDisplayed)
  2603. {
  2604. NcMsgBox(_Module.GetResourceInstance(),
  2605. m_hWnd,
  2606. IDS_LAN_CAPTION,
  2607. IDS_LANUI_SHARING_CONFLICT,
  2608. MB_ICONINFORMATION | MB_OK);
  2609. }
  2610. }
  2611. else
  2612. {
  2613. NcRasMsgBoxWithErrorText (HRESULT_CODE(hr),
  2614. _Module.GetResourceInstance(), m_hWnd,
  2615. IDS_LANUI_ERROR_CAPTION, IDS_TEXT_WITH_RAS_ERROR,
  2616. m_fShared ? IDS_LAN_UNSHARE_FAILED : IDS_LAN_SHARE_FAILED,
  2617. MB_OK | MB_ICONEXCLAMATION );
  2618. }
  2619. }
  2620. }
  2621. else if (m_fResetPrivateAdapter && m_cPrivate)
  2622. {
  2623. if (m_cPrivate > 1)
  2624. {
  2625. HWND hWndCb = GetDlgItem(IDC_CB_PrivateLan);
  2626. INT item = ComboBox_GetCurSel(hWndCb);
  2627. if (item != CB_ERR)
  2628. {
  2629. pPrivateConn =
  2630. (IHNetConnection*)ComboBox_GetItemData(hWndCb, item);
  2631. }
  2632. }
  2633. else
  2634. {
  2635. ASSERT(NULL != m_rgPrivateCons);
  2636. pPrivateConn = m_rgPrivateCons[0];
  2637. }
  2638. hr = pPrivateConn->SharePrivate(&pIcsPrivate);
  2639. if (SUCCEEDED(hr))
  2640. {
  2641. ReleaseObj(pIcsPrivate);
  2642. }
  2643. else
  2644. {
  2645. HRESULT hr2 = m_pHNetIcsSettings->DisableIcs(&ulcPub, &ulcPvt);
  2646. if (SUCCEEDED(hr2))
  2647. {
  2648. m_fShared = FALSE;
  2649. }
  2650. NcRasMsgBoxWithErrorText (HRESULT_CODE(hr),
  2651. _Module.GetResourceInstance(), m_hWnd,
  2652. IDS_LANUI_ERROR_CAPTION, IDS_TEXT_WITH_RAS_ERROR,
  2653. m_fShared ? IDS_LAN_UNSHARE_FAILED : IDS_LAN_SHARE_FAILED,
  2654. MB_OK | MB_ICONEXCLAMATION );
  2655. }
  2656. }
  2657. HKEY hKey;
  2658. if(ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, REGKEY_SHAREDACCESSCLIENTKEYPATH, 0, NULL, 0, KEY_SET_VALUE, NULL, &hKey, NULL))
  2659. {
  2660. DWORD dwData = BST_CHECKED == IsDlgButtonChecked(IDC_CHK_BeaconControl);
  2661. RegSetValueEx(hKey, REGVAL_SHAREDACCESSCLIENTENABLECONTROL, 0, REG_DWORD, reinterpret_cast<LPBYTE>(&dwData), sizeof(dwData));
  2662. RegCloseKey(hKey);
  2663. }
  2664. TraceError("CLanAdvancedPage::OnApply", hr);
  2665. //
  2666. // We always need to return a success code here. If we return a failure
  2667. // code the dialog won't go away, allowing the user to click "OK" a
  2668. // second time. This second call will result in problems w/ other
  2669. // property sheets (e.g., CLanNetPage), as they aren't expecting this
  2670. // second (non-reentrant) call to OnApply.
  2671. //
  2672. if (FAILED(hr))
  2673. {
  2674. hr = S_FALSE;
  2675. }
  2676. return LresFromHr(hr);
  2677. }
  2678. //+---------------------------------------------------------------------------
  2679. //
  2680. // Member: CLanAdvancedPage::OnCancel
  2681. //
  2682. // Purpose: Called when the 'Shared Access' page is cancelled.
  2683. //
  2684. // Arguments:
  2685. // idCtrl []
  2686. // pnmh []
  2687. // bHandled []
  2688. //
  2689. // Returns:
  2690. //
  2691. // Author: aboladeg 14 May 1998
  2692. //
  2693. // Notes:
  2694. //
  2695. LRESULT CLanAdvancedPage::OnCancel(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  2696. {
  2697. TraceFileFunc(ttidLanUi);
  2698. return LresFromHr(S_OK);
  2699. }
  2700. //+---------------------------------------------------------------------------
  2701. //
  2702. // Member: CLanAdvancedPage::OnKillActive
  2703. //
  2704. // Purpose: Called when the 'Shared Access' page is deactivated,
  2705. // or applied.
  2706. //
  2707. // Arguments:
  2708. // idCtrl []
  2709. // pnmh []
  2710. // bHandled []
  2711. //
  2712. // Returns:
  2713. //
  2714. // Author: aboladeg 6 July 1998
  2715. //
  2716. // Notes:
  2717. //
  2718. LRESULT CLanAdvancedPage::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  2719. {
  2720. TraceFileFunc(ttidLanUi);
  2721. //
  2722. // m_fOtherShared will be set to true in OnShared if we're switching the
  2723. // shared connection. Since we've already displayed a warning for
  2724. // switching, we don't need to display another here.
  2725. //
  2726. if (IsDlgButtonChecked(IDC_CHK_Shared) && (!m_fShared || (m_fResetPrivateAdapter && 0 != m_cPrivate)))
  2727. {
  2728. IHNetConnection* pPrivateConn = NULL;
  2729. if(1 < m_cPrivate) // if the combobox is showing make sure they selected a valid adapter
  2730. {
  2731. HWND hwndCb = GetDlgItem(IDC_CB_PrivateLan);
  2732. INT item = ComboBox_GetCurSel(hwndCb);
  2733. if (item != CB_ERR)
  2734. {
  2735. pPrivateConn = reinterpret_cast<IHNetConnection*>(ComboBox_GetItemData(hwndCb, item));
  2736. }
  2737. }
  2738. else
  2739. {
  2740. pPrivateConn = m_rgPrivateCons[0];
  2741. }
  2742. if(NULL == pPrivateConn)
  2743. {
  2744. Assert(1 < m_cPrivate);
  2745. NcMsgBox(_Module.GetResourceInstance(), m_hWnd, IDS_LAN_CAPTION,
  2746. IDS_SHAREDACCESS_SELECTADAPTERERROR, MB_OK | MB_ICONWARNING);
  2747. SetWindowLong(DWLP_MSGRESULT, PSNRET_INVALID);
  2748. return TRUE;
  2749. }
  2750. if(!m_fOtherShared && FALSE == IsAdapterDHCPEnabled(pPrivateConn))
  2751. {
  2752. int nRet = NcMsgBox(
  2753. _Module.GetResourceInstance(), m_hWnd, IDS_LAN_CAPTION,
  2754. IDS_LAN_ENABLE_SHARED_ACCESS, MB_ICONINFORMATION|MB_YESNO);
  2755. if (nRet == IDNO)
  2756. {
  2757. SetWindowLong(DWLP_MSGRESULT, TRUE);
  2758. return TRUE;
  2759. }
  2760. }
  2761. }
  2762. if (TRUE == m_fFirewalled && TRUE == m_fShowDisableFirewallWarning && BST_UNCHECKED == IsDlgButtonChecked(IDC_CHK_Firewall))
  2763. {
  2764. INT_PTR nDialogResult;
  2765. m_fShowDisableFirewallWarning = FALSE;
  2766. nDialogResult = DialogBox(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_DISABLEFIREWALLWARNING), m_hWnd, DisableFirewallWarningDlgProc);
  2767. if(-1 != nDialogResult && IDYES != nDialogResult)
  2768. {
  2769. CheckDlgButton(IDC_CHK_Firewall, BST_CHECKED);
  2770. ::EnableWindow(
  2771. GetDlgItem(IDC_PSB_Settings),
  2772. BST_CHECKED == IsDlgButtonChecked(IDC_CHK_Firewall) || BST_CHECKED == IsDlgButtonChecked(IDC_CHK_Shared)
  2773. );
  2774. }
  2775. }
  2776. return FALSE;
  2777. }
  2778. //+---------------------------------------------------------------------------
  2779. //
  2780. // Member: CLanAdvancedPage::OnShared
  2781. //
  2782. // Purpose: Handles the clicking of the Shared button
  2783. //
  2784. // Arguments:
  2785. // wNotifyCode []
  2786. // wID []
  2787. // hWndCtl []
  2788. // bHandled []
  2789. //
  2790. // Returns:
  2791. //
  2792. // Author: aboladeg 23 May 1998
  2793. //
  2794. // Notes:
  2795. //
  2796. LRESULT CLanAdvancedPage::OnShared(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  2797. BOOL& bHandled)
  2798. {
  2799. TraceFileFunc(ttidLanUi);
  2800. BOOL fShared = IsDlgButtonChecked(IDC_CHK_Shared);
  2801. if (!m_fShared && fShared)
  2802. {
  2803. //
  2804. // Check to see if the user is changing the shared connection
  2805. //
  2806. HRESULT hr = S_OK;
  2807. IHNetIcsPublicConnection* pOldIcsConn;
  2808. IHNetConnection* pOldConn;
  2809. PWSTR pszwOld;
  2810. NETCON_PROPERTIES* pProps;
  2811. IEnumHNetIcsPublicConnections *pEnum;
  2812. hr = m_pHNetIcsSettings->EnumIcsPublicConnections(&pEnum);
  2813. if (SUCCEEDED(hr))
  2814. {
  2815. ULONG ulCount;
  2816. hr = pEnum->Next(1, &pOldIcsConn, &ulCount);
  2817. if (SUCCEEDED(hr) && 1 == ulCount)
  2818. {
  2819. hr = pOldIcsConn->QueryInterface(
  2820. __uuidof(pOldConn),
  2821. reinterpret_cast<void**>(&pOldConn)
  2822. );
  2823. if (SUCCEEDED(hr))
  2824. {
  2825. hr = pOldConn->GetName(&pszwOld);
  2826. ReleaseObj(pOldConn);
  2827. //
  2828. // Transfer reference for old shared connection
  2829. //
  2830. m_pOldSharedConnection = pOldIcsConn;
  2831. //
  2832. // Even if we weren't able to obtain the name of the
  2833. // old shared connection, we need to note that such
  2834. // a connection exists. (This situation will arise if
  2835. // the old shared connection has been removed from the
  2836. // system.)
  2837. //
  2838. m_fOtherShared = TRUE;
  2839. }
  2840. else
  2841. {
  2842. ReleaseObj(pOldIcsConn);
  2843. }
  2844. }
  2845. else
  2846. {
  2847. m_fOtherShared = FALSE;
  2848. }
  2849. ReleaseObj(pEnum);
  2850. }
  2851. if (SUCCEEDED(hr) && m_fOtherShared)
  2852. {
  2853. hr = m_pconn->GetProperties(&pProps);
  2854. if (SUCCEEDED(hr))
  2855. {
  2856. NcMsgBox(
  2857. _Module.GetResourceInstance(), m_hWnd, IDS_LANUI_ERROR_CAPTION,
  2858. IDS_LAN_CHANGE_SHARED_CONNECTION, MB_ICONINFORMATION|MB_OK,
  2859. pszwOld, pProps->pszwName );
  2860. FreeNetconProperties(pProps);
  2861. }
  2862. CoTaskMemFree(pszwOld);
  2863. }
  2864. }
  2865. ::EnableWindow(GetDlgItem(IDC_PSB_Settings), fShared || BST_CHECKED == IsDlgButtonChecked(IDC_CHK_Firewall));
  2866. ::EnableWindow(GetDlgItem(IDC_CHK_BeaconControl), fShared);
  2867. return LresFromHr(S_OK);
  2868. }
  2869. //+---------------------------------------------------------------------------
  2870. //
  2871. // Member: CLanAdvancedPage::OnFirewall
  2872. //
  2873. // Purpose: Handles the clicking of the Firewall checkbox
  2874. //
  2875. // Arguments:
  2876. // wNotifyCode []
  2877. // wID []
  2878. // hWndCtl []
  2879. // bHandled []
  2880. //
  2881. // Returns:
  2882. //
  2883. // Author: jonburs 6 Oct 1999
  2884. //
  2885. // Notes:
  2886. //
  2887. LRESULT CLanAdvancedPage::OnFirewall(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  2888. BOOL& bHandled)
  2889. {
  2890. TraceFileFunc(ttidLanUi);
  2891. ::EnableWindow(
  2892. GetDlgItem(IDC_PSB_Settings),
  2893. BST_CHECKED == IsDlgButtonChecked(IDC_CHK_Firewall) || BST_CHECKED == IsDlgButtonChecked(IDC_CHK_Shared)
  2894. );
  2895. return LresFromHr(S_OK);
  2896. }
  2897. //+---------------------------------------------------------------------------
  2898. //
  2899. // Member: CLanAdvancedPage::OnSettings
  2900. //
  2901. // Purpose: Handles the clicking of the Settings button
  2902. //
  2903. // Arguments:
  2904. // wNotifyCode []
  2905. // wID []
  2906. // hWndCtl []
  2907. // bHandled []
  2908. //
  2909. // Returns:
  2910. //
  2911. // Author: aboladeg 25 Oct 1998
  2912. //
  2913. // Notes:
  2914. //
  2915. LRESULT CLanAdvancedPage::OnSettings(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  2916. BOOL& bHandled)
  2917. {
  2918. DWORD dwLastError = NOERROR;
  2919. TraceFileFunc(ttidLanUi);
  2920. HINSTANCE hinstance = LoadLibrary(TEXT("hnetcfg.dll"));
  2921. if (!hinstance)
  2922. dwLastError = GetLastError();
  2923. else {
  2924. BOOL (APIENTRY *pfnHNetSharingAndFirewallSettingsDlg)(HWND, IHNetCfgMgr*, BOOL, IHNetConnection*);
  2925. pfnHNetSharingAndFirewallSettingsDlg = (BOOL (APIENTRY *)(HWND, IHNetCfgMgr*, BOOL, IHNetConnection*))
  2926. ::GetProcAddress(hinstance, "HNetSharingAndFirewallSettingsDlg");
  2927. if (!pfnHNetSharingAndFirewallSettingsDlg)
  2928. dwLastError = GetLastError();
  2929. else
  2930. pfnHNetSharingAndFirewallSettingsDlg(m_hWnd, m_pHNetCfgMgr, IsDlgButtonChecked(IDC_CHK_Firewall), m_pHNetConn);
  2931. FreeLibrary (hinstance);
  2932. }
  2933. if (dwLastError != NOERROR) {
  2934. LPVOID lpMsgBuf = NULL;
  2935. if (FormatMessage(
  2936. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  2937. FORMAT_MESSAGE_FROM_SYSTEM |
  2938. FORMAT_MESSAGE_IGNORE_INSERTS,
  2939. NULL,
  2940. dwLastError,
  2941. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  2942. (LPTSTR) &lpMsgBuf,
  2943. 0,
  2944. NULL)) {
  2945. // Display the string.
  2946. MessageBox( (LPCTSTR)lpMsgBuf );
  2947. // Free the buffer.
  2948. LocalFree( lpMsgBuf );
  2949. }
  2950. }
  2951. return LresFromHr(S_OK);
  2952. }
  2953. //+---------------------------------------------------------------------------
  2954. //
  2955. // Member: CLanAdvancedPage::OnClick
  2956. //
  2957. // Purpose: Called in response to the NM_CLICK message
  2958. //
  2959. // Arguments:
  2960. // idCtrl []
  2961. // pnmh []
  2962. // fHandled []
  2963. //
  2964. // Returns:
  2965. //
  2966. // Author: kenwic 11 Sep 2000
  2967. //
  2968. // Notes:
  2969. //
  2970. LRESULT CLanAdvancedPage::OnClick(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  2971. {
  2972. TraceFileFunc(ttidLanUi);
  2973. if(IDC_ST_HNWLINK == idCtrl)
  2974. {
  2975. HWND hPropertySheetWindow = GetParent();
  2976. if(NULL != hPropertySheetWindow)
  2977. {
  2978. ShellExecute(NULL,TEXT("open"),TEXT("rundll32"), TEXT("hnetwiz.dll,HomeNetWizardRunDll"),NULL,SW_SHOW);
  2979. ::PostMessage(hPropertySheetWindow, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM) ::GetDlgItem(hPropertySheetWindow, IDCANCEL));
  2980. }
  2981. }
  2982. else if(IDC_ST_ICFLINK == idCtrl || IDC_ST_ICSLINK == idCtrl)
  2983. {
  2984. LPTSTR pszHelpTopic = IDC_ST_ICFLINK == idCtrl ? TEXT("netcfg.chm::/hnw_understanding_firewall.htm") : TEXT("netcfg.chm::/Share_conn_overvw.htm");
  2985. HtmlHelp(NULL, pszHelpTopic, HH_DISPLAY_TOPIC, 0);
  2986. }
  2987. return 0;
  2988. }
  2989. INT_PTR CALLBACK CLanAdvancedPage::DisableFirewallWarningDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2990. {
  2991. TraceFileFunc(ttidLanUi);
  2992. switch(uMsg)
  2993. {
  2994. case WM_COMMAND:
  2995. {
  2996. switch(LOWORD(wParam))
  2997. {
  2998. case IDYES:
  2999. case IDNO:
  3000. if(BST_CHECKED == ::IsDlgButtonChecked(hWnd, IDC_CHK_DISABLEFIREWALLWARNING))
  3001. {
  3002. HKEY hFirewallKey;
  3003. if(SUCCEEDED(HrRegCreateKeyEx(HKEY_CURRENT_USER, g_pszFirewallRegKey, 0, KEY_SET_VALUE, NULL, &hFirewallKey, NULL)))
  3004. {
  3005. DWORD dwValue = TRUE;
  3006. HrRegSetValueEx(hFirewallKey, g_pszDisableFirewallWarningValue, REG_DWORD, reinterpret_cast<CONST BYTE*>(&dwValue), sizeof(dwValue));
  3007. RegCloseKey(hFirewallKey);
  3008. }
  3009. }
  3010. // fallthru
  3011. case IDCANCEL:
  3012. EndDialog(hWnd, LOWORD(wParam));
  3013. break;
  3014. }
  3015. break;
  3016. }
  3017. }
  3018. return FALSE;
  3019. }
  3020. //+---------------------------------------------------------------------------
  3021. //
  3022. // Member: CLanAdvancedPage::IsAdapterDHCPEnabled
  3023. //
  3024. // Purpose: Check if DHCP is set on this adapter
  3025. //
  3026. // Arguments:
  3027. // pConnection: the adapter
  3028. //
  3029. // Returns:
  3030. //
  3031. // Author: kenwic 11 Oct 2000
  3032. //
  3033. // Notes:
  3034. //
  3035. BOOL CLanAdvancedPage::IsAdapterDHCPEnabled(IHNetConnection* pConnection)
  3036. {
  3037. TraceFileFunc(ttidLanUi);
  3038. HRESULT hr;
  3039. BOOL fDHCP = FALSE;
  3040. GUID* pAdapterGuid;
  3041. hr = pConnection->GetGuid(&pAdapterGuid);
  3042. if(SUCCEEDED(hr))
  3043. {
  3044. LPOLESTR pAdapterName;
  3045. hr = StringFromCLSID(*pAdapterGuid, &pAdapterName);
  3046. if(SUCCEEDED(hr))
  3047. {
  3048. SIZE_T Length = wcslen(pAdapterName);
  3049. LPSTR pszAnsiAdapterName = new char[Length + 1];
  3050. if(NULL != pszAnsiAdapterName)
  3051. {
  3052. if(0 != WideCharToMultiByte(CP_ACP, 0, pAdapterName, Length + 1, pszAnsiAdapterName, Length + 1, NULL, NULL))
  3053. {
  3054. HMODULE hIpHelper;
  3055. hIpHelper = LoadLibrary(L"iphlpapi");
  3056. if(NULL != hIpHelper)
  3057. {
  3058. DWORD (WINAPI *pGetAdaptersInfo)(PIP_ADAPTER_INFO, PULONG);
  3059. pGetAdaptersInfo = (DWORD (WINAPI*)(PIP_ADAPTER_INFO, PULONG)) GetProcAddress(hIpHelper, "GetAdaptersInfo");
  3060. if(NULL != pGetAdaptersInfo)
  3061. {
  3062. ULONG ulSize = 0;
  3063. if(ERROR_BUFFER_OVERFLOW == pGetAdaptersInfo(NULL, &ulSize))
  3064. {
  3065. BYTE* pInfoArray = new BYTE[ulSize];
  3066. PIP_ADAPTER_INFO pInfo = reinterpret_cast<PIP_ADAPTER_INFO>(pInfoArray);
  3067. if(NULL != pInfo)
  3068. {
  3069. if(ERROR_SUCCESS == pGetAdaptersInfo(pInfo, &ulSize))
  3070. {
  3071. PIP_ADAPTER_INFO pAdapterInfo = pInfo;
  3072. do
  3073. {
  3074. if(0 == lstrcmpA(pszAnsiAdapterName, pAdapterInfo->AdapterName))
  3075. {
  3076. fDHCP = !!pAdapterInfo->DhcpEnabled;
  3077. break;
  3078. }
  3079. } while(NULL != (pAdapterInfo = pAdapterInfo->Next));
  3080. }
  3081. delete [] pInfoArray;
  3082. }
  3083. }
  3084. }
  3085. FreeLibrary(hIpHelper);
  3086. }
  3087. }
  3088. delete [] pszAnsiAdapterName;
  3089. }
  3090. CoTaskMemFree(pAdapterName);
  3091. }
  3092. CoTaskMemFree(pAdapterGuid);
  3093. }
  3094. return fDHCP;
  3095. }
  3096. //
  3097. // CLanAddComponentDlg
  3098. //
  3099. struct ADD_COMPONENT_INFO
  3100. {
  3101. UINT uiIdsName;
  3102. UINT uiIdsDesc;
  3103. const GUID * pguidClass;
  3104. };
  3105. static const ADD_COMPONENT_INFO c_rgaci[] =
  3106. {
  3107. {IDS_LAN_CLIENT, IDS_LAN_CLIENT_DESC, &GUID_DEVCLASS_NETCLIENT},
  3108. {IDS_LAN_SERVICE, IDS_LAN_SERVICE_DESC, &GUID_DEVCLASS_NETSERVICE},
  3109. {IDS_LAN_PROTOCOL, IDS_LAN_PROTOCOL_DESC, &GUID_DEVCLASS_NETTRANS},
  3110. };
  3111. static const INT c_naci = celems(c_rgaci);
  3112. //+---------------------------------------------------------------------------
  3113. //
  3114. // Member: CLanAddComponentDlg::OnInitDialog
  3115. //
  3116. // Purpose: Handles the WM_INITDIALOG message
  3117. //
  3118. // Arguments:
  3119. // uMsg []
  3120. // wParam []
  3121. // lParam []
  3122. // bHandled []
  3123. //
  3124. // Returns:
  3125. //
  3126. // Author: danielwe 29 Oct 1997
  3127. //
  3128. // Notes:
  3129. //
  3130. LRESULT CLanAddComponentDlg::OnInitDialog(UINT uMsg, WPARAM wParam,
  3131. LPARAM lParam, BOOL& bHandled)
  3132. {
  3133. TraceFileFunc(ttidLanUi);
  3134. HRESULT hr = S_OK;
  3135. INT iaci;
  3136. RECT rc;
  3137. LV_COLUMN lvc = {0};
  3138. SP_CLASSIMAGELIST_DATA cid = {0};
  3139. BOOL fValidImages = FALSE;
  3140. m_hwndLV = GetDlgItem(IDC_LVW_Lan_Components);
  3141. // Get the class image list structure
  3142. hr = HrSetupDiGetClassImageList(&cid);
  3143. if (SUCCEEDED(hr))
  3144. {
  3145. ListView_SetImageList(m_hwndLV, ImageList_Duplicate(cid.ImageList),
  3146. LVSIL_SMALL);
  3147. fValidImages = TRUE;
  3148. }
  3149. else
  3150. {
  3151. // Handling failure with fValidImages flag
  3152. hr = S_OK;
  3153. }
  3154. ::GetClientRect(m_hwndLV, &rc);
  3155. lvc.mask = LVCF_FMT | LVCF_WIDTH;
  3156. lvc.fmt = LVCFMT_LEFT;
  3157. lvc.cx = rc.right - GetSystemMetrics(SM_CXVSCROLL);
  3158. ListView_InsertColumn(m_hwndLV, 0, &lvc);
  3159. // For each class, add it to the list
  3160. for (iaci = 0; iaci < c_naci; iaci++)
  3161. {
  3162. LV_ITEM lvi = {0};
  3163. lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_PARAM;
  3164. if (fValidImages)
  3165. {
  3166. // Get the component's class image list index
  3167. hr = HrSetupDiGetClassImageIndex(&cid,
  3168. const_cast<LPGUID>(c_rgaci[iaci].pguidClass),
  3169. &lvi.iImage);
  3170. if (SUCCEEDED(hr))
  3171. {
  3172. lvi.mask |= LVIF_IMAGE;
  3173. }
  3174. }
  3175. // Select the first item
  3176. if (iaci == 0)
  3177. {
  3178. lvi.state = lvi.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  3179. }
  3180. lvi.pszText = const_cast<PWSTR>(SzLoadIds(c_rgaci[iaci].uiIdsName));
  3181. lvi.lParam = reinterpret_cast<LPARAM>(c_rgaci[iaci].pguidClass);
  3182. lvi.iItem = iaci;
  3183. ListView_InsertItem(m_hwndLV, &lvi);
  3184. }
  3185. if (fValidImages)
  3186. {
  3187. (void) HrSetupDiDestroyClassImageList(&cid);
  3188. }
  3189. if (FAILED(hr))
  3190. {
  3191. EndDialog(0);
  3192. }
  3193. TraceError("CLanAddComponentDlg::OnInitDialog", hr);
  3194. return TRUE;
  3195. }
  3196. //+---------------------------------------------------------------------------
  3197. //
  3198. // Member: CLanAddComponentDlg::OnContextMenu
  3199. //
  3200. // Purpose: When right click a control, bring up help
  3201. //
  3202. // Arguments: Standard command parameters
  3203. //
  3204. // Returns: Standard return
  3205. //
  3206. LRESULT
  3207. CLanAddComponentDlg::OnContextMenu(UINT uMsg,
  3208. WPARAM wParam,
  3209. LPARAM lParam,
  3210. BOOL& fHandled)
  3211. {
  3212. TraceFileFunc(ttidLanUi);
  3213. if (m_adwHelpIDs != NULL)
  3214. {
  3215. ::WinHelp(m_hWnd,
  3216. c_szNetCfgHelpFile,
  3217. HELP_CONTEXTMENU,
  3218. (ULONG_PTR)m_adwHelpIDs);
  3219. }
  3220. return 0;
  3221. }
  3222. //+---------------------------------------------------------------------------
  3223. //
  3224. // Member: CLanAddComponentDlg::OnHelp
  3225. //
  3226. // Purpose: When drag context help icon over a control, bring up help
  3227. //
  3228. // Arguments: Standard command parameters
  3229. //
  3230. // Returns: Standard return
  3231. //
  3232. LRESULT
  3233. CLanAddComponentDlg::OnHelp( UINT uMsg,
  3234. WPARAM wParam,
  3235. LPARAM lParam,
  3236. BOOL& fHandled)
  3237. {
  3238. TraceFileFunc(ttidLanUi);
  3239. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  3240. Assert(lphi);
  3241. if ((m_adwHelpIDs != NULL) && (HELPINFO_WINDOW == lphi->iContextType))
  3242. {
  3243. ::WinHelp(static_cast<HWND>(lphi->hItemHandle),
  3244. c_szNetCfgHelpFile,
  3245. HELP_WM_HELP,
  3246. (ULONG_PTR)m_adwHelpIDs);
  3247. }
  3248. return 0;
  3249. }
  3250. //+---------------------------------------------------------------------------
  3251. //
  3252. // Member: CLanAddComponentDlg::OnItemChanged
  3253. //
  3254. // Purpose: Handles the selection changed message for the list view
  3255. //
  3256. // Arguments:
  3257. // idCtrl []
  3258. // pnmh []
  3259. // bHandled []
  3260. //
  3261. // Returns:
  3262. //
  3263. // Author: danielwe 29 Oct 1997
  3264. //
  3265. // Notes:
  3266. //
  3267. LRESULT CLanAddComponentDlg::OnItemChanged(int idCtrl, LPNMHDR pnmh,
  3268. BOOL& bHandled)
  3269. {
  3270. TraceFileFunc(ttidLanUi);
  3271. NM_LISTVIEW * pnmlv = reinterpret_cast<NM_LISTVIEW *>(pnmh);
  3272. HWND hwndButton = GetDlgItem(IDC_PSB_Component_Add);
  3273. Assert(pnmlv);
  3274. // Check if selection changed
  3275. if ((pnmlv->uNewState & LVIS_SELECTED) &&
  3276. (!(pnmlv->uOldState & LVIS_SELECTED)))
  3277. {
  3278. // Update the description if/when selection changes
  3279. SetDlgItemText(IDC_TXT_Component_Desc,
  3280. SzLoadIds(c_rgaci[pnmlv->iItem].uiIdsDesc));
  3281. ::EnableWindow(hwndButton, TRUE);
  3282. }
  3283. else if (!(pnmlv->uNewState & LVIS_SELECTED) &&
  3284. (pnmlv->uOldState & LVIS_SELECTED))
  3285. {
  3286. // Update the description if/when selection changes
  3287. SetDlgItemText(IDC_TXT_Component_Desc, c_szEmpty);
  3288. ::EnableWindow(hwndButton, FALSE);
  3289. }
  3290. return 0;
  3291. }
  3292. //+---------------------------------------------------------------------------
  3293. //
  3294. // Member: CLanAddComponentDlg::OnAdd
  3295. //
  3296. // Purpose: Handles the clicking of the Add button
  3297. //
  3298. // Arguments:
  3299. // wNotifyCode []
  3300. // wID []
  3301. // hWndCtl []
  3302. // bHandled []
  3303. //
  3304. // Returns:
  3305. //
  3306. // Author: danielwe 29 Oct 1997
  3307. //
  3308. // Notes:
  3309. //
  3310. LRESULT CLanAddComponentDlg::OnAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  3311. BOOL& bHandled)
  3312. {
  3313. TraceFileFunc(ttidLanUi);
  3314. HRESULT hr = S_OK;
  3315. INT iIndex;
  3316. INetCfgComponent * pncc = NULL;
  3317. BOOL fCancel = FALSE;
  3318. HWND hwndFocus;
  3319. CWaitCursor wc; // Displays a wait cursor
  3320. // Get the selected item
  3321. iIndex = ListView_GetNextItem(m_hwndLV, -1, LVNI_SELECTED);
  3322. if (iIndex != -1)
  3323. {
  3324. int rgidc[] = {IDC_LVW_Lan_Components, IDC_PSB_Component_Add, IDCANCEL};
  3325. CWaitCursor wc;
  3326. LV_ITEM lvi = {0};
  3327. lvi.mask = LVIF_PARAM;
  3328. lvi.iItem = iIndex;
  3329. ListView_GetItem(m_hwndLV, &lvi);
  3330. // Disable the UI
  3331. //
  3332. hwndFocus = ::GetFocus();
  3333. EnableOrDisableDialogControls (m_hWnd, celems(rgidc), rgidc, FALSE);
  3334. // This is its class GUID.
  3335. //
  3336. Assert (lvi.lParam);
  3337. // Get the setup interface for the class and use it to install
  3338. // a component of the user's selection.
  3339. //
  3340. GUID* pClassGuid = (GUID*)lvi.lParam;
  3341. INetCfgInternalSetup* pInternalSetup;
  3342. hr = m_pnc->QueryInterface (IID_INetCfgInternalSetup,
  3343. (void**)&pInternalSetup);
  3344. if (SUCCEEDED(hr))
  3345. {
  3346. OBO_TOKEN OboToken;
  3347. ZeroMemory (&OboToken, sizeof(OboToken));
  3348. OboToken.Type = OBO_USER;
  3349. hr = pInternalSetup->SelectWithFilterAndInstall(m_hWnd,
  3350. pClassGuid, &OboToken, m_pcfi, &pncc);
  3351. if (HRESULT_FROM_WIN32 (ERROR_CANCELLED) == hr)
  3352. {
  3353. fCancel = TRUE;
  3354. hr = S_FALSE;
  3355. }
  3356. else if (S_OK == hr)
  3357. {
  3358. // Commit the changes
  3359. hr = m_pnc->Apply();
  3360. }
  3361. ReleaseObj(pncc);
  3362. ReleaseObj(pInternalSetup);
  3363. }
  3364. EnableOrDisableDialogControls (m_hWnd, celems(rgidc), rgidc, TRUE);
  3365. ::SetFocus( hwndFocus );
  3366. }
  3367. else
  3368. {
  3369. fCancel = TRUE;
  3370. }
  3371. if (SUCCEEDED(hr) && (NETCFG_S_REBOOT != hr))
  3372. {
  3373. // Make sure S_FALSE doesn't get thru
  3374. hr = S_OK;
  3375. }
  3376. if (!fCancel)
  3377. {
  3378. // Return the installed error code as the result. S_OK means user
  3379. // clicked OK and actually added a component. S_FALSE means they
  3380. // cancelled, otherwise this will return an error code
  3381. EndDialog(static_cast<int>(hr));
  3382. }
  3383. TraceError("CLanAddComponentDlg::OnAdd", hr);
  3384. return 0;
  3385. }
  3386. //+---------------------------------------------------------------------------
  3387. //
  3388. // Member: CLanAddComponentDlg::OnCancel
  3389. //
  3390. // Purpose: Called when the cancel button is pressed.
  3391. //
  3392. // Arguments:
  3393. // wNotifyCode []
  3394. // wID []
  3395. // hWndCtl []
  3396. // bHandled []
  3397. //
  3398. // Returns:
  3399. //
  3400. // Author: danielwe 10 Nov 1997
  3401. //
  3402. // Notes:
  3403. //
  3404. LRESULT CLanAddComponentDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  3405. BOOL& bHandled)
  3406. {
  3407. TraceFileFunc(ttidLanUi);
  3408. HRESULT hr = S_FALSE;
  3409. // Return S_FALSE on cancel
  3410. EndDialog(static_cast<int>(hr));
  3411. return 0;
  3412. }
  3413. LRESULT CLanAddComponentDlg::OnDblClick(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  3414. {
  3415. TraceFileFunc(ttidLanUi);
  3416. return OnAdd(0, 0, NULL, bHandled);
  3417. }
  3418. //
  3419. // CLanSecurityPage
  3420. //
  3421. CLanSecurityPage::CLanSecurityPage(
  3422. IUnknown* punk,
  3423. INetCfg* pnc,
  3424. INetConnection* pconn,
  3425. const DWORD * adwHelpIDs)
  3426. {
  3427. TraceFileFunc(ttidLanUi);
  3428. m_pconn = pconn;
  3429. m_pnc = pnc;
  3430. m_fNetcfgInUse = FALSE;
  3431. m_adwHelpIDs = adwHelpIDs;
  3432. pListEapcfgs = NULL;
  3433. }
  3434. //+---------------------------------------------------------------------------
  3435. //
  3436. // Member: CLanSecurityPage::~CLanSecurityPage
  3437. //
  3438. // Purpose: Destroys the CLanSecurityPage object
  3439. //
  3440. // Arguments:
  3441. // (none)
  3442. //
  3443. // Returns: Nothing
  3444. //
  3445. // Author: sachins
  3446. //
  3447. // Notes:
  3448. //
  3449. CLanSecurityPage::~CLanSecurityPage()
  3450. {
  3451. TraceFileFunc(ttidLanUi);
  3452. }
  3453. //+---------------------------------------------------------------------------
  3454. //
  3455. // Member: CLanSecurityPage::OnInitDialog
  3456. //
  3457. // Purpose: Handles the WM_INITDIALOG message
  3458. //
  3459. // Arguments:
  3460. // uMsg []
  3461. // wParam []
  3462. // lParam []
  3463. // bHandled []
  3464. //
  3465. // Returns: error code
  3466. //
  3467. // Author: sachins
  3468. //
  3469. // Notes:
  3470. //
  3471. LRESULT CLanSecurityPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  3472. LPARAM lParam, BOOL& bHandled)
  3473. {
  3474. TraceFileFunc(ttidLanUi);
  3475. DTLNODE* pOriginalEapcfgNode = NULL;
  3476. WCHAR wszGuid[c_cchGuidWithTerm];
  3477. BYTE *pbData = NULL;
  3478. DWORD cbData = 0;
  3479. EAPOL_INTF_PARAMS EapolIntfParams;
  3480. EAPOL_INTF_STATE EapolIntfState = {0};
  3481. BOOLEAN fFlag = FALSE;
  3482. DWORD dwFlags = 0;
  3483. HRESULT hr = S_OK;
  3484. SetClassLongPtr(m_hWnd, GCLP_HCURSOR, NULL);
  3485. SetClassLongPtr(GetParent(), GCLP_HCURSOR, NULL);
  3486. // Initially disable all the controls
  3487. ::EnableWindow(GetDlgItem(CID_CA_RB_Eap), FALSE);
  3488. ::EnableWindow(GetDlgItem(IDC_TXT_EAP_TYPE), FALSE);
  3489. ::EnableWindow(GetDlgItem(CID_CA_LB_EapPackages), FALSE);
  3490. ::EnableWindow(GetDlgItem(CID_CA_PB_Properties), FALSE);
  3491. ::EnableWindow(GetDlgItem(CID_CA_RB_MachineAuth), FALSE);
  3492. ::EnableWindow(GetDlgItem(CID_CA_RB_GuestAuth), FALSE);
  3493. // Initialize EAP package list
  3494. // Read the EAPCFG information from the registry and find the node
  3495. // selected in the entry, or the default, if none.
  3496. do
  3497. {
  3498. DTLNODE* pNode = NULL;
  3499. TCHAR* pszEncEnabled = NULL;
  3500. DTLNODE* pNodeEap;
  3501. DWORD dwkey = 0;
  3502. NETCON_PROPERTIES* pProps;
  3503. hr = m_pconn->GetProperties(&pProps);
  3504. if (SUCCEEDED(hr))
  3505. {
  3506. if ((::StringFromGUID2(pProps->guidId,
  3507. wszGuid,
  3508. c_cchGuidWithTerm)) == 0)
  3509. {
  3510. TraceTag (ttidLanUi, "Security::OnInitDialog: StringFromGUID2 failed");
  3511. FreeNetconProperties(pProps);
  3512. break;
  3513. }
  3514. FreeNetconProperties(pProps);
  3515. }
  3516. else
  3517. {
  3518. TraceTag (ttidLanUi, "Security::OnInitDialog: GetProperties failed");
  3519. break;
  3520. }
  3521. // Read the state for this interface
  3522. ZeroMemory ((BYTE *)&EapolIntfState, sizeof(EAPOL_INTF_STATE));
  3523. DWORD dwRetCode = NO_ERROR;
  3524. dwRetCode = WZCEapolQueryState (
  3525. NULL,
  3526. wszGuid,
  3527. &EapolIntfState
  3528. );
  3529. if (dwRetCode != NO_ERROR)
  3530. {
  3531. TraceTag (ttidLanUi, "WZCEapolQueryState failed with error %ld",
  3532. dwRetCode);
  3533. // Consider the interface as non-wireless
  3534. }
  3535. // Read the EAP params for this interface
  3536. ZeroMemory ((BYTE *)&EapolIntfParams, sizeof(EAPOL_INTF_PARAMS));
  3537. EapolIntfParams.dwEapFlags = DEFAULT_EAP_STATE;
  3538. EapolIntfParams.dwEapType = DEFAULT_EAP_TYPE;
  3539. hr = HrElGetInterfaceParams (
  3540. wszGuid,
  3541. &EapolIntfParams
  3542. );
  3543. if (FAILED (hr))
  3544. {
  3545. TraceTag (ttidLanUi, "HrElGetInterfaceParams failed with error %ld",
  3546. LresFromHr(hr));
  3547. break;
  3548. }
  3549. // Read the EAPCFG information from the registry and find the node
  3550. // selected in the entry, or the default, if none.
  3551. pListEapcfgs = NULL;
  3552. if (EapolIntfState.dwPhysicalMediumType == NdisPhysicalMediumWirelessLan)
  3553. {
  3554. dwFlags |= EAPOL_MUTUAL_AUTH_EAP_ONLY;
  3555. }
  3556. pListEapcfgs = ::ReadEapcfgList (dwFlags);
  3557. if (pListEapcfgs)
  3558. {
  3559. TraceTag (ttidLanUi, "HrElGetInterfaceParams: Got EAPtype=(%ld), EAPState =(%ld)", EapolIntfParams.dwEapType, EapolIntfParams.dwEapFlags);
  3560. // Enable all windows only for admins
  3561. // if (FIsUserAdmin())
  3562. {
  3563. fFlag = TRUE;
  3564. }
  3565. ::EnableWindow(GetDlgItem(CID_CA_RB_Eap), fFlag);
  3566. if (IS_EAPOL_ENABLED(EapolIntfParams.dwEapFlags))
  3567. {
  3568. Button_SetCheck(GetDlgItem(CID_CA_RB_Eap), TRUE);
  3569. CheckDlgButton(CID_CA_RB_Eap, TRUE);
  3570. ::EnableWindow(GetDlgItem(IDC_TXT_EAP_TYPE), fFlag);
  3571. ::EnableWindow(GetDlgItem(CID_CA_LB_EapPackages), fFlag);
  3572. ::EnableWindow(GetDlgItem(CID_CA_RB_MachineAuth), fFlag);
  3573. if (IS_MACHINE_AUTH_ENABLED(EapolIntfParams.dwEapFlags))
  3574. Button_SetCheck(GetDlgItem(CID_CA_RB_MachineAuth), TRUE);
  3575. ::EnableWindow(GetDlgItem(CID_CA_RB_GuestAuth), fFlag);
  3576. if (IS_GUEST_AUTH_ENABLED(EapolIntfParams.dwEapFlags))
  3577. Button_SetCheck(GetDlgItem(CID_CA_RB_GuestAuth), TRUE);
  3578. }
  3579. else
  3580. {
  3581. ::EnableWindow(GetDlgItem(CID_CA_RB_MachineAuth), FALSE);
  3582. if (IS_MACHINE_AUTH_ENABLED(EapolIntfParams.dwEapFlags))
  3583. Button_SetCheck(GetDlgItem(CID_CA_RB_MachineAuth), TRUE);
  3584. ::EnableWindow(GetDlgItem(CID_CA_RB_GuestAuth), FALSE);
  3585. if (IS_GUEST_AUTH_ENABLED(EapolIntfParams.dwEapFlags))
  3586. Button_SetCheck(GetDlgItem(CID_CA_RB_GuestAuth), TRUE);
  3587. }
  3588. // Read the EAP configuration info for all EAP packages
  3589. for (pNodeEap = DtlGetFirstNode(pListEapcfgs);
  3590. pNodeEap;
  3591. pNodeEap = DtlGetNextNode(pNodeEap))
  3592. {
  3593. EAPCFG* pEapcfg = (EAPCFG* )DtlGetData(pNodeEap);
  3594. ASSERT( pEapcfg );
  3595. hr = S_OK;
  3596. TraceTag (ttidLanUi, "Calling HrElGetCustomAuthData for EAP %ld",
  3597. pEapcfg->dwKey);
  3598. cbData = 0;
  3599. // Get the size of the EAP blob
  3600. hr = HrElGetCustomAuthData (
  3601. wszGuid,
  3602. pEapcfg->dwKey,
  3603. EapolIntfParams.dwSizeOfSSID,
  3604. EapolIntfParams.bSSID,
  3605. NULL,
  3606. &cbData
  3607. );
  3608. if (!SUCCEEDED(hr))
  3609. {
  3610. if ((EapolIntfParams.dwSizeOfSSID != 0) &&
  3611. (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)))
  3612. {
  3613. TraceTag (ttidLanUi, "HrElGetCustomAuthData: SSID!= NULL, not found blob for SSID");
  3614. // The Last Used SSID did not have a connection
  3615. // blob created. Call again for size of blob with
  3616. // NULL SSID
  3617. EapolIntfParams.dwSizeOfSSID = 0;
  3618. // Get the size of the EAP blob
  3619. hr = HrElGetCustomAuthData (
  3620. wszGuid,
  3621. pEapcfg->dwKey,
  3622. 0,
  3623. NULL,
  3624. NULL,
  3625. &cbData
  3626. );
  3627. }
  3628. if (hr == E_OUTOFMEMORY)
  3629. {
  3630. if (cbData <= 0)
  3631. {
  3632. // No EAP blob stored in the registry
  3633. TraceTag (ttidLanUi, "HrElGetCustomAuthData: No blob stored in reg at all");
  3634. pbData = NULL;
  3635. // Will continue processing for errors
  3636. // Not exit
  3637. }
  3638. else
  3639. {
  3640. TraceTag (ttidLanUi, "HrElGetCustomAuthData: Found auth blob in registry");
  3641. // Allocate memory to hold the blob
  3642. pbData = (PBYTE) MALLOC (cbData);
  3643. if (pbData == NULL)
  3644. {
  3645. hr = E_OUTOFMEMORY;
  3646. TraceTag (ttidLanUi, "HrElGetCustomAuthData: Error in memory allocation for EAP blob");
  3647. continue;
  3648. }
  3649. ZeroMemory (pbData, cbData);
  3650. hr = HrElGetCustomAuthData (
  3651. wszGuid,
  3652. pEapcfg->dwKey,
  3653. EapolIntfParams.dwSizeOfSSID,
  3654. EapolIntfParams.bSSID,
  3655. pbData,
  3656. &cbData
  3657. );
  3658. if (!SUCCEEDED(hr))
  3659. {
  3660. TraceTag (ttidLanUi, "HrElGetCustomAuthData: HrElGetCustomAuthData failed with %ld",
  3661. LresFromHr(hr));
  3662. FREE ( pbData );
  3663. hr = S_OK;
  3664. continue;
  3665. }
  3666. TraceTag (ttidLanUi, "HrElGetCustomAuthData: HrElGetCustomAuthData successfully got blob of length %ld"
  3667. , cbData);
  3668. }
  3669. }
  3670. else
  3671. {
  3672. TraceTag (ttidLanUi, "HrElGetCustomAuthData: Not got ERROR_NOT_ENOUGH_MEMORY error; Unknown error !!!");
  3673. continue;
  3674. }
  3675. }
  3676. else
  3677. {
  3678. // HrElGetCustomAuthData will always return
  3679. // error with cbData = 0
  3680. }
  3681. if (pEapcfg->pData != NULL)
  3682. {
  3683. FREE ( pEapcfg->pData );
  3684. }
  3685. pEapcfg->pData = (UCHAR *)pbData;
  3686. pEapcfg->cbData = cbData;
  3687. }
  3688. // Choose the EAP name that will appear in the combo box
  3689. pNode = EapcfgNodeFromKey(
  3690. pListEapcfgs, EapolIntfParams.dwEapType );
  3691. pOriginalEapcfgNode = pNode;
  3692. // Fill the EAP packages listbox and select the previously identified
  3693. // selection. The Properties button is disabled by default, but may
  3694. // be enabled when the EAP list selection is set.
  3695. ::EnableWindow(GetDlgItem(CID_CA_PB_Properties), FALSE);
  3696. for (pNode = DtlGetFirstNode( pListEapcfgs );
  3697. pNode;
  3698. pNode = DtlGetNextNode( pNode ))
  3699. {
  3700. EAPCFG* pEapcfg = NULL;
  3701. INT i;
  3702. TCHAR* pszBuf = NULL;
  3703. pEapcfg = (EAPCFG* )DtlGetData( pNode );
  3704. ASSERT( pEapcfg );
  3705. ASSERT( pEapcfg->pszFriendlyName );
  3706. pszBuf = (TCHAR *) MALLOC (( lstrlen(pEapcfg->pszFriendlyName) + 1 ) * sizeof(TCHAR));
  3707. if (!pszBuf)
  3708. {
  3709. continue;
  3710. }
  3711. lstrcpy( pszBuf, pEapcfg->pszFriendlyName );
  3712. i = ComboBox_AddItem( GetDlgItem(CID_CA_LB_EapPackages),
  3713. pszBuf, pNode );
  3714. if (pNode == pOriginalEapcfgNode)
  3715. {
  3716. // Select the EAP name that will appear in the
  3717. // combo box
  3718. ComboBox_SetCurSelNotify( GetDlgItem(CID_CA_LB_EapPackages), i );
  3719. }
  3720. FREE ( pszBuf );
  3721. }
  3722. }
  3723. ComboBox_AutoSizeDroppedWidth( GetDlgItem(CID_CA_LB_EapPackages) );
  3724. // Disable the Properties button, if EAPOL is not enabled
  3725. // or if the user is not AdminUser
  3726. // if ((!FIsUserAdmin()) || (!IS_EAPOL_ENABLED(EapolIntfParams.dwEapFlags)))
  3727. if ((!IS_EAPOL_ENABLED(EapolIntfParams.dwEapFlags)))
  3728. {
  3729. ::EnableWindow (GetDlgItem(CID_CA_PB_Properties), FALSE);
  3730. }
  3731. } while (FALSE);
  3732. return LresFromHr(hr);
  3733. }
  3734. //+---------------------------------------------------------------------------
  3735. //
  3736. // Member: CLanSecurityPage::OnContextMenu
  3737. //
  3738. // Purpose: When right click a control, bring up help
  3739. //
  3740. // Arguments: Standard command parameters
  3741. //
  3742. // Returns:
  3743. //
  3744. // Author: sachins
  3745. //
  3746. LRESULT
  3747. CLanSecurityPage::OnContextMenu(UINT uMsg,
  3748. WPARAM wParam,
  3749. LPARAM lParam,
  3750. BOOL& fHandled)
  3751. {
  3752. TraceFileFunc(ttidLanUi);
  3753. if (m_adwHelpIDs != NULL)
  3754. {
  3755. ::WinHelp(m_hWnd,
  3756. c_szNetCfgHelpFile,
  3757. HELP_CONTEXTMENU,
  3758. (ULONG_PTR)m_adwHelpIDs);
  3759. }
  3760. return 0;
  3761. }
  3762. //+---------------------------------------------------------------------------
  3763. //
  3764. // Member: CLanSecurityPage::OnHelp
  3765. //
  3766. // Purpose: When drag context help icon over a control, bring up help
  3767. //
  3768. // Arguments: Standard command parameters
  3769. //
  3770. // Returns:
  3771. //
  3772. // Author: sachins
  3773. //
  3774. LRESULT
  3775. CLanSecurityPage::OnHelp( UINT uMsg,
  3776. WPARAM wParam,
  3777. LPARAM lParam,
  3778. BOOL& fHandled)
  3779. {
  3780. TraceFileFunc(ttidLanUi);
  3781. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  3782. Assert(lphi);
  3783. if ((m_adwHelpIDs != NULL) && (HELPINFO_WINDOW == lphi->iContextType))
  3784. {
  3785. ::WinHelp(static_cast<HWND>(lphi->hItemHandle),
  3786. c_szNetCfgHelpFile,
  3787. HELP_WM_HELP,
  3788. (ULONG_PTR)m_adwHelpIDs);
  3789. }
  3790. return 0;
  3791. }
  3792. //+---------------------------------------------------------------------------
  3793. //
  3794. // Member: CLanSecurityPage::OnDestroy
  3795. //
  3796. // Purpose: Called when the dialog page is destroyed
  3797. //
  3798. // Arguments:
  3799. // uMsg []
  3800. // wParam []
  3801. // lParam []
  3802. // bHandled []
  3803. //
  3804. // Returns:
  3805. //
  3806. // Author: sachins
  3807. //
  3808. // Notes:
  3809. //
  3810. LRESULT CLanSecurityPage::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam,
  3811. BOOL& bHandled)
  3812. {
  3813. TraceFileFunc(ttidLanUi);
  3814. if (pListEapcfgs)
  3815. {
  3816. DtlDestroyList (pListEapcfgs, DestroyEapcfgNode);
  3817. }
  3818. pListEapcfgs = NULL;
  3819. return 0;
  3820. }
  3821. //+---------------------------------------------------------------------------
  3822. //
  3823. // Member: CLanSecurityPage::OnProperties
  3824. //
  3825. // Purpose: Handles the clicking of the Properties button
  3826. //
  3827. // Arguments:
  3828. // wNotifyCode []
  3829. // wID []
  3830. // hWndCtl []
  3831. // bHandled []
  3832. //
  3833. // Returns: error code
  3834. //
  3835. // Author: sachins
  3836. //
  3837. // Notes:
  3838. //
  3839. LRESULT CLanSecurityPage::OnProperties(WORD wNotifyCode, WORD wID,
  3840. HWND hWndCtl, BOOL& bHandled)
  3841. {
  3842. TraceFileFunc(ttidLanUi);
  3843. DWORD dwErr = 0;
  3844. DTLNODE* pNode = NULL;
  3845. EAPCFG* pEapcfg = NULL;
  3846. RASEAPINVOKECONFIGUI pInvokeConfigUi;
  3847. RASEAPFREE pFreeConfigUIData;
  3848. HINSTANCE h;
  3849. BYTE* pConnectionData = NULL;
  3850. DWORD cbConnectionData = 0;
  3851. HRESULT hr = S_OK;
  3852. // Look up the selected package configuration and load the associated
  3853. // configuration DLL.
  3854. pNode = (DTLNODE* )ComboBox_GetItemDataPtr(
  3855. GetDlgItem(CID_CA_LB_EapPackages),
  3856. ComboBox_GetCurSel( GetDlgItem(CID_CA_LB_EapPackages) ) );
  3857. ASSERT( pNode );
  3858. if (!pNode)
  3859. {
  3860. return E_UNEXPECTED;
  3861. }
  3862. pEapcfg = (EAPCFG* )DtlGetData( pNode );
  3863. ASSERT( pEapcfg );
  3864. h = NULL;
  3865. if (!(h = LoadLibrary( pEapcfg->pszConfigDll ))
  3866. || !(pInvokeConfigUi =
  3867. (RASEAPINVOKECONFIGUI )GetProcAddress(
  3868. h, "RasEapInvokeConfigUI" ))
  3869. || !(pFreeConfigUIData =
  3870. (RASEAPFREE) GetProcAddress(
  3871. h, "RasEapFreeMemory" )))
  3872. {
  3873. // Cannot load configuration DLL
  3874. if (h)
  3875. {
  3876. FreeLibrary( h );
  3877. }
  3878. return E_FAIL;
  3879. }
  3880. // Call the configuration DLL to popup it's custom configuration UI.
  3881. pConnectionData = NULL;
  3882. cbConnectionData = 0;
  3883. dwErr = pInvokeConfigUi(
  3884. pEapcfg->dwKey,
  3885. GetParent(),
  3886. RAS_EAP_FLAG_8021X_AUTH,
  3887. pEapcfg->pData,
  3888. pEapcfg->cbData,
  3889. &pConnectionData,
  3890. &cbConnectionData
  3891. );
  3892. if (dwErr != 0)
  3893. {
  3894. FreeLibrary( h );
  3895. return E_FAIL;
  3896. }
  3897. // Store the configuration information returned in the package descriptor.
  3898. FREE ( pEapcfg->pData );
  3899. pEapcfg->pData = NULL;
  3900. pEapcfg->cbData = 0;
  3901. if (pConnectionData)
  3902. {
  3903. if (cbConnectionData > 0)
  3904. {
  3905. // Copy it into the eap node
  3906. pEapcfg->pData = (PUCHAR) MALLOC (cbConnectionData);
  3907. if (pEapcfg->pData)
  3908. {
  3909. CopyMemory( pEapcfg->pData, pConnectionData, cbConnectionData );
  3910. pEapcfg->cbData = cbConnectionData;
  3911. }
  3912. }
  3913. }
  3914. pFreeConfigUIData( pConnectionData );
  3915. // Note any "force user to configure" requirement on the package has been
  3916. // satisfied.
  3917. pEapcfg->fConfigDllCalled = TRUE;
  3918. FreeLibrary( h );
  3919. TraceError("CLanSecurityPage::OnProperties", hr);
  3920. return LresFromHr(hr);
  3921. }
  3922. //+---------------------------------------------------------------------------
  3923. //
  3924. // Member: CLanSecurityPage::OnEapSelection
  3925. //
  3926. // Purpose: Handles the clicking of the EAP checkbox
  3927. //
  3928. // Arguments:
  3929. // wNotifyCode []
  3930. // wID []
  3931. // hWndCtl []
  3932. // bHandled []
  3933. //
  3934. // Returns:
  3935. //
  3936. // Author: sachins
  3937. //
  3938. // Notes:
  3939. //
  3940. LRESULT CLanSecurityPage::OnEapSelection(WORD wNotifyCode, WORD wID,
  3941. HWND hWndCtl, BOOL& bHandled)
  3942. {
  3943. TraceFileFunc(ttidLanUi);
  3944. HRESULT hr = S_OK;
  3945. EAPCFG* pEapcfg = NULL;
  3946. INT iSel = 0;
  3947. // Toggle buttons based on selection
  3948. if (BST_CHECKED == IsDlgButtonChecked(CID_CA_RB_Eap))
  3949. {
  3950. ::EnableWindow(GetDlgItem(CID_CA_LB_EapPackages), TRUE);
  3951. ::EnableWindow(GetDlgItem(IDC_TXT_EAP_TYPE), TRUE);
  3952. // Get the EAPCFG information for the currently selected EAP package.
  3953. iSel = ComboBox_GetCurSel(GetDlgItem(CID_CA_LB_EapPackages));
  3954. // iSel is the index in the displayed list as well as the
  3955. // index of the dll that are loaded.
  3956. // Get the cfgnode corresponding to this index
  3957. if (iSel >= 0)
  3958. {
  3959. DTLNODE* pNode;
  3960. pNode =
  3961. (DTLNODE* )ComboBox_GetItemDataPtr(
  3962. GetDlgItem(CID_CA_LB_EapPackages), iSel );
  3963. if (pNode)
  3964. {
  3965. pEapcfg = (EAPCFG* )DtlGetData( pNode );
  3966. }
  3967. }
  3968. // Enable the Properties button if the selected package has a
  3969. // configuration entrypoint
  3970. // if (FIsUserAdmin())
  3971. {
  3972. ::EnableWindow ( GetDlgItem(CID_CA_PB_Properties),
  3973. (pEapcfg && !!(pEapcfg->pszConfigDll)) );
  3974. }
  3975. ::EnableWindow(GetDlgItem(CID_CA_RB_MachineAuth), TRUE);
  3976. ::EnableWindow(GetDlgItem(CID_CA_RB_GuestAuth), TRUE);
  3977. }
  3978. else
  3979. {
  3980. ::EnableWindow(GetDlgItem (IDC_TXT_EAP_TYPE), FALSE);
  3981. ::EnableWindow(GetDlgItem (CID_CA_LB_EapPackages), FALSE);
  3982. ::EnableWindow(GetDlgItem (CID_CA_PB_Properties), FALSE);
  3983. ::EnableWindow(GetDlgItem(CID_CA_RB_MachineAuth), FALSE);
  3984. ::EnableWindow(GetDlgItem(CID_CA_RB_GuestAuth), FALSE);
  3985. }
  3986. TraceError("CLanSecurityPage::OnEapSelection", hr);
  3987. return LresFromHr(hr);
  3988. }
  3989. //+---------------------------------------------------------------------------
  3990. //
  3991. // Member: CLanSecurityPage::OnEapPackages
  3992. //
  3993. // Purpose: Handles the clicking of the EAP packages combo box
  3994. //
  3995. // Arguments:
  3996. // wNotifyCode []
  3997. // wID []
  3998. // hWndCtl []
  3999. // bHandled []
  4000. //
  4001. // Returns:
  4002. //
  4003. // Author: sachins
  4004. //
  4005. // Notes:
  4006. //
  4007. LRESULT CLanSecurityPage::OnEapPackages(WORD wNotifyCode, WORD wID,
  4008. HWND hWndCtl, BOOL& bHandled)
  4009. {
  4010. TraceFileFunc(ttidLanUi);
  4011. HRESULT hr = S_OK;
  4012. EAPCFG* pEapcfg = NULL;
  4013. INT iSel = 0;
  4014. // Get the EAPCFG information for the selected EAP package.
  4015. iSel = ComboBox_GetCurSel(GetDlgItem(CID_CA_LB_EapPackages));
  4016. // iSel is the index in the displayed list as well as the
  4017. // index of the dll that are loaded.
  4018. // Get the cfgnode corresponding to this index
  4019. if (iSel >= 0)
  4020. {
  4021. DTLNODE* pNode = NULL;
  4022. pNode =
  4023. (DTLNODE* )ComboBox_GetItemDataPtr(
  4024. GetDlgItem(CID_CA_LB_EapPackages), iSel );
  4025. if (pNode)
  4026. {
  4027. pEapcfg = (EAPCFG* )DtlGetData( pNode );
  4028. }
  4029. }
  4030. // Enable the Properties button if the selected package has a
  4031. // configuration entrypoint
  4032. if (BST_CHECKED == IsDlgButtonChecked(CID_CA_RB_Eap))
  4033. {
  4034. ::EnableWindow ( GetDlgItem(CID_CA_PB_Properties),
  4035. (pEapcfg && !!(pEapcfg?pEapcfg->pszConfigDll:NULL)) );
  4036. }
  4037. TraceError("CLanSecurityPage::OnEapPackages", hr);
  4038. return LresFromHr(hr);
  4039. }
  4040. //+---------------------------------------------------------------------------
  4041. //
  4042. // Member: CLanSecurityPage::OnKillActive
  4043. //
  4044. // Purpose: Called to check warning conditions before the security
  4045. // page is going away
  4046. //
  4047. // Arguments:
  4048. // idCtrl []
  4049. // pnmh []
  4050. // bHandled []
  4051. //
  4052. // Returns:
  4053. //
  4054. // Author: sachins
  4055. //
  4056. // Notes:
  4057. //
  4058. LRESULT CLanSecurityPage::OnKillActive(int idCtrl, LPNMHDR pnmh,
  4059. BOOL& bHandled)
  4060. {
  4061. TraceFileFunc(ttidLanUi);
  4062. BOOL fError;
  4063. fError = m_fNetcfgInUse;
  4064. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, fError);
  4065. return fError;
  4066. }
  4067. //+---------------------------------------------------------------------------
  4068. //
  4069. // Member: CLanSecurityPage::OnApply
  4070. //
  4071. // Purpose: Called when the Networking page is applied
  4072. //
  4073. // Arguments:
  4074. // idCtrl []
  4075. // pnmh []
  4076. // bHandled []
  4077. //
  4078. // Returns:
  4079. //
  4080. // Author: sachins
  4081. //
  4082. // Notes:
  4083. //
  4084. LRESULT CLanSecurityPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  4085. {
  4086. TraceFileFunc(ttidLanUi);
  4087. WCHAR wszGuid[c_cchGuidWithTerm];
  4088. WCHAR *pwszLastUsedSSID = NULL;
  4089. DWORD dwSizeofSSID = 0;
  4090. DWORD dwEapFlags = 0;
  4091. DWORD dwDefaultEapType = 0;
  4092. EAPOL_INTF_PARAMS EapolIntfParams;
  4093. NETCON_PROPERTIES* pProps = NULL;
  4094. HRESULT hrOverall = S_OK;
  4095. HRESULT hr = S_OK;
  4096. // Save the EAP configuration data into the registry
  4097. DTLNODE* pNodeEap = NULL;
  4098. #if 0
  4099. if (!FIsUserAdmin())
  4100. {
  4101. TraceTag (ttidLanUi, "CLanSecurityPage::OnApply: Non-admin user, not saving data");
  4102. return LresFromHr(hr);
  4103. }
  4104. #endif
  4105. hr = m_pconn->GetProperties(&pProps);
  4106. if (!SUCCEEDED(hr))
  4107. {
  4108. TraceTag (ttidLanUi, "CLanSecurityPage::OnApply: Error in m_pconn->GetProperties");
  4109. return LresFromHr(hr);
  4110. }
  4111. hr = S_OK;
  4112. if (::StringFromGUID2(pProps->guidId, wszGuid, c_cchGuidWithTerm) == 0)
  4113. {
  4114. TraceTag (ttidLanUi, "CLanSecurityPage::OnApply: StringFromGUID2 failed");
  4115. FreeNetconProperties(pProps);
  4116. hr = E_FAIL;
  4117. return LresFromHr(hr);
  4118. }
  4119. FreeNetconProperties(pProps);
  4120. // Get the Last Used SSID on the interface and set the
  4121. // EAP blob for that interface
  4122. ZeroMemory ((BYTE *)&EapolIntfParams, sizeof(EAPOL_INTF_PARAMS));
  4123. EapolIntfParams.dwEapFlags = DEFAULT_EAP_STATE;
  4124. hr = HrElGetInterfaceParams (
  4125. wszGuid,
  4126. &EapolIntfParams
  4127. );
  4128. if (FAILED(hr))
  4129. {
  4130. TraceTag (ttidLanUi, "OnApply: HrElGetInterfaceParams failed with error %ld",
  4131. LresFromHr(hr));
  4132. return LresFromHr(hr);
  4133. }
  4134. // Save data for all EAP packages in the registry
  4135. if (pListEapcfgs == NULL)
  4136. {
  4137. return LresFromHr(S_OK);
  4138. }
  4139. {
  4140. DTLNODE* pNode = NULL;
  4141. EAPCFG* pEapcfg = NULL;
  4142. pNode = (DTLNODE* )ComboBox_GetItemDataPtr(
  4143. GetDlgItem (CID_CA_LB_EapPackages),
  4144. ComboBox_GetCurSel( GetDlgItem (CID_CA_LB_EapPackages) ) );
  4145. if (pNode == NULL)
  4146. {
  4147. return LresFromHr (E_FAIL);
  4148. }
  4149. pEapcfg = (EAPCFG* )DtlGetData( pNode );
  4150. if (pEapcfg == NULL)
  4151. {
  4152. return LresFromHr (E_FAIL);
  4153. }
  4154. dwDefaultEapType = pEapcfg->dwKey;
  4155. }
  4156. for (pNodeEap = DtlGetFirstNode(pListEapcfgs);
  4157. pNodeEap;
  4158. pNodeEap = DtlGetNextNode(pNodeEap))
  4159. {
  4160. EAPCFG* pcfg = (EAPCFG* )DtlGetData(pNodeEap);
  4161. if (pcfg == NULL)
  4162. {
  4163. continue;
  4164. }
  4165. hr = S_OK;
  4166. TraceTag (ttidLanUi, "Saving data for EAP Id = %ld", pcfg->dwKey);
  4167. TraceTag (ttidLanUi, "OnApply: Setting customauthdata for %S",
  4168. wszGuid);
  4169. // ignore error and continue with next
  4170. hr = HrElSetCustomAuthData (
  4171. wszGuid,
  4172. pcfg->dwKey,
  4173. EapolIntfParams.dwSizeOfSSID,
  4174. EapolIntfParams.bSSID,
  4175. pcfg->pData,
  4176. pcfg->cbData);
  4177. if (FAILED (hr))
  4178. {
  4179. TraceTag (ttidLanUi, "HrElSetCustomAuthData failed");
  4180. hrOverall = hr;
  4181. hr = S_OK;
  4182. }
  4183. else
  4184. {
  4185. TraceTag (ttidLanUi, "HrElSetCustomAuthData succeeded");
  4186. }
  4187. FREE (pcfg->pData);
  4188. pcfg->pData = NULL;
  4189. pcfg->cbData = 0;
  4190. }
  4191. // If CID_CA_RB_Eap is checked, EAPOL is enabled on the interface
  4192. if ( Button_GetCheck( GetDlgItem(CID_CA_RB_Eap) ) )
  4193. {
  4194. dwEapFlags |= EAPOL_ENABLED;
  4195. if (Button_GetCheck( GetDlgItem(CID_CA_RB_MachineAuth )))
  4196. dwEapFlags |= EAPOL_MACHINE_AUTH_ENABLED;
  4197. if (Button_GetCheck( GetDlgItem(CID_CA_RB_GuestAuth )))
  4198. dwEapFlags |= EAPOL_GUEST_AUTH_ENABLED;
  4199. // Save the params for this interface in registry
  4200. EapolIntfParams.dwEapType = dwDefaultEapType;
  4201. EapolIntfParams.dwEapFlags = dwEapFlags;
  4202. hr = HrElSetInterfaceParams (
  4203. wszGuid,
  4204. &EapolIntfParams
  4205. );
  4206. if (FAILED(hr))
  4207. {
  4208. TraceTag (ttidLanUi, "HrElSetInterfaceParams enabled failed with error %ld",
  4209. LresFromHr(hr));
  4210. hrOverall = hr;
  4211. hr = S_OK;
  4212. }
  4213. }
  4214. else
  4215. {
  4216. dwEapFlags |= EAPOL_DISABLED;
  4217. if (Button_GetCheck( GetDlgItem(CID_CA_RB_MachineAuth )))
  4218. dwEapFlags |= EAPOL_MACHINE_AUTH_ENABLED;
  4219. if (Button_GetCheck( GetDlgItem(CID_CA_RB_GuestAuth )))
  4220. dwEapFlags |= EAPOL_GUEST_AUTH_ENABLED;
  4221. // Save the params for this interface in registry
  4222. EapolIntfParams.dwEapType = dwDefaultEapType;
  4223. EapolIntfParams.dwEapFlags = dwEapFlags;
  4224. hr = HrElSetInterfaceParams (
  4225. wszGuid,
  4226. &EapolIntfParams
  4227. );
  4228. if (FAILED(hr))
  4229. {
  4230. TraceTag (ttidLanUi, "HrElSetInterfaceParams EAPOL disabled failed with error %ld",
  4231. LresFromHr(hr));
  4232. hrOverall = hr;
  4233. hr = S_OK;
  4234. }
  4235. }
  4236. if (FAILED(hrOverall))
  4237. {
  4238. NcMsgBox(
  4239. WZCGetSPResModule(),
  4240. m_hWnd,
  4241. IDS_LANUI_ERROR_CAPTION,
  4242. IDS_EAPOL_PARTIAL_APPLY,
  4243. MB_ICONSTOP|MB_OK);
  4244. }
  4245. return LresFromHr(hr);
  4246. }
  4247. //+---------------------------------------------------------------------------
  4248. //
  4249. // Member: CLanSecurityPage::OnCancel
  4250. //
  4251. // Purpose: Called when the Networking page is cancelled.
  4252. //
  4253. // Arguments:
  4254. // idCtrl []
  4255. // pnmh []
  4256. // bHandled []
  4257. //
  4258. // Returns:
  4259. //
  4260. // Author: sachins
  4261. //
  4262. //
  4263. LRESULT CLanSecurityPage::OnCancel(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  4264. {
  4265. TraceFileFunc(ttidLanUi);
  4266. if (pListEapcfgs)
  4267. {
  4268. DtlDestroyList (pListEapcfgs, DestroyEapcfgNode);
  4269. }
  4270. pListEapcfgs = NULL;
  4271. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, m_fNetcfgInUse);
  4272. return m_fNetcfgInUse;
  4273. }