Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5186 lines
151 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 = (int)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 connection 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 adapter 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: NcRasMsgBoxWithErrorText
  2057. //
  2058. // Purpose: Displays a message box using a RAS or Win32 error code,
  2059. // resource strings and replaceable parameters.
  2060. // The output text is a combination of the user's format
  2061. // string (with parameter's replaced) and the Win32 error
  2062. // text as returned from FormatMessage. These two strings
  2063. // are combined using the IDS_TEXT_WITH_WIN32_ERROR resource.
  2064. //
  2065. // Arguments:
  2066. // dwError [in] RAS/Win32 error code
  2067. // hinst [in] Module instance where string resources live.
  2068. // hwnd [in] parent window handle
  2069. // unIdCaption [in] resource id of caption string
  2070. // unIdCombineFormat [in] resource id of format string to combine
  2071. // error text with unIdFormat text.
  2072. // unIdFormat [in] resource id of text string (with %1, %2, etc.)
  2073. // unStyle [in] standard message box styles
  2074. // ... [in] replaceable parameters (optional)
  2075. // (these must be PCWSTRs as that is all
  2076. // FormatMessage handles.)
  2077. //
  2078. // Returns: the return value of MessageBox()
  2079. //
  2080. // Author: aboladeg 15 May 1997
  2081. //
  2082. // Notes: FormatMessage is used to do the parameter substitution.
  2083. //
  2084. // Revision: based on NcMsgBoxWithWin32ErrorText by shaunco.
  2085. //
  2086. NOTHROW
  2087. int
  2088. WINAPIV
  2089. NcRasMsgBoxWithErrorText (
  2090. DWORD dwError,
  2091. HINSTANCE hinst,
  2092. HWND hwnd,
  2093. UINT unIdCaption,
  2094. UINT unIdCombineFormat,
  2095. UINT unIdFormat,
  2096. UINT unStyle,
  2097. ...)
  2098. {
  2099. // Get the user's text with parameter's replaced.
  2100. //
  2101. PCWSTR pszFormat = SzLoadString (hinst, unIdFormat);
  2102. PWSTR pszText;
  2103. va_list val;
  2104. va_start (val, unStyle);
  2105. FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
  2106. pszFormat, 0, 0, (PWSTR)&pszText, 0, &val);
  2107. va_end(val);
  2108. // Get the error text for the Win32 error.
  2109. //
  2110. PWSTR pszError = NULL;
  2111. if (dwError < RASBASE || dwError > RASBASEEND)
  2112. {
  2113. FormatMessage (
  2114. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  2115. NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  2116. (PWSTR)&pszError, 0, NULL);
  2117. }
  2118. else
  2119. {
  2120. pszError = (PWSTR)LocalAlloc (0, (512 + 1) * sizeof(WCHAR));
  2121. if (pszError)
  2122. {
  2123. RasGetErrorString(dwError, pszError, 512);
  2124. }
  2125. }
  2126. // Combine the user's text with the error text using IDS_TEXT_WITH_WIN32_ERROR.
  2127. //
  2128. PCWSTR pszTextWithErrorFmt = SzLoadString (hinst, unIdCombineFormat);
  2129. PWSTR pszTextWithError;
  2130. DwFormatStringWithLocalAlloc (pszTextWithErrorFmt, &pszTextWithError,
  2131. pszText, pszError);
  2132. PCWSTR pszCaption = SzLoadString (hinst, unIdCaption);
  2133. int nRet = MessageBox(hwnd, pszTextWithError, pszCaption, unStyle);
  2134. LocalFree (pszTextWithError);
  2135. LocalFree (pszError);
  2136. LocalFree (pszText);
  2137. return nRet;
  2138. }
  2139. //+---------------------------------------------------------------------------
  2140. //
  2141. // Function: HrQueryLanAdvancedPage
  2142. //
  2143. // Purpose: Determines whether the 'Shared Access' page should be shown,
  2144. // and if so supplies an initialized object for the page.
  2145. // The page is displayed if
  2146. // (a) the user is an admin or power-user, and
  2147. // (b) TCP/IP is installed, and
  2148. // (i) this is already a shared connection, or
  2149. // (ii) there is at least one other LAN connection.
  2150. //
  2151. // Arguments:
  2152. // pconn [in] the connection for which a page is requested
  2153. // pspAdvanced[out] the created page, if appropriate
  2154. //
  2155. // Returns: S_OK if success, Win32 error otherwise
  2156. //
  2157. // Author: aboladeg 22 Aug 1998
  2158. //
  2159. // Notes:
  2160. //
  2161. HRESULT HrQueryLanAdvancedPage(INetConnection* pconn, IUnknown* punk,
  2162. CPropSheetPage*& pspAdvanced, IHNetCfgMgr *pHNetCfgMgr,
  2163. IHNetIcsSettings *pHNetIcsSettings,
  2164. IHNetConnection *pHNetConn)
  2165. {
  2166. HRESULT hr = S_OK;
  2167. TraceFileFunc(ttidLanUi);
  2168. pspAdvanced = NULL;
  2169. BOOL fShared = FALSE;
  2170. BOOL fAnyShared = FALSE;
  2171. HNET_CONN_PROPERTIES *pHNetProps;
  2172. IHNetConnection **rgPrivateCons;
  2173. ULONG cPrivate;
  2174. LONG lxCurrentPrivate;
  2175. //
  2176. // (i) Determine if this connection is currently shared
  2177. //
  2178. hr = pHNetConn->GetProperties(&pHNetProps);
  2179. if (FAILED(hr))
  2180. {
  2181. return hr;
  2182. }
  2183. if(FALSE == pHNetProps->fPartOfBridge && FALSE == pHNetProps->fBridge) // no sharing a bridged adapter or the bridge
  2184. {
  2185. fShared = pHNetProps->fIcsPublic;
  2186. // (ii) Determine what connections could serve as a private connection
  2187. // if pconn were made the public connection
  2188. //
  2189. hr = pHNetIcsSettings->GetPossiblePrivateConnections(
  2190. pHNetConn,
  2191. &cPrivate,
  2192. &rgPrivateCons,
  2193. &lxCurrentPrivate
  2194. );
  2195. if (SUCCEEDED(hr))
  2196. {
  2197. pspAdvanced = new CLanAdvancedPage(punk, pconn, fShared, pHNetProps->fIcsPrivate, pHNetProps->fFirewalled, rgPrivateCons,
  2198. cPrivate, lxCurrentPrivate,
  2199. g_aHelpIDs_IDD_LAN_ADVANCED,
  2200. pHNetConn, pHNetCfgMgr, pHNetIcsSettings);
  2201. }
  2202. }
  2203. CoTaskMemFree(pHNetProps);
  2204. return S_OK;
  2205. }
  2206. CLanAdvancedPage::CLanAdvancedPage(IUnknown *punk, INetConnection *pconn,
  2207. BOOL fShared, BOOL fICSPrivate, BOOL fFirewalled, IHNetConnection **rgPrivateCons,
  2208. ULONG cPrivate, LONG lxCurrentPrivate,
  2209. const DWORD * adwHelpIDs, IHNetConnection *pHNConn,
  2210. IHNetCfgMgr *pHNetCfgMgr, IHNetIcsSettings *pHNetIcsSettings)
  2211. {
  2212. TraceFileFunc(ttidLanUi);
  2213. m_pconn = pconn;
  2214. m_punk = punk;
  2215. m_fShared = fShared;
  2216. m_fICSPrivate = fICSPrivate;
  2217. m_fFirewalled = fFirewalled;
  2218. m_fOtherShared = FALSE;
  2219. m_pOldSharedConnection = NULL;
  2220. m_fResetPrivateAdapter = fShared && -1 == lxCurrentPrivate;
  2221. m_rgPrivateCons = rgPrivateCons;
  2222. m_cPrivate = cPrivate;
  2223. m_lxCurrentPrivate = lxCurrentPrivate;
  2224. m_adwHelpIDs = adwHelpIDs;
  2225. m_pHNetCfgMgr = pHNetCfgMgr;
  2226. AddRefObj(m_pHNetCfgMgr);
  2227. m_pHNetIcsSettings = pHNetIcsSettings;
  2228. AddRefObj(m_pHNetIcsSettings);
  2229. m_pHNetConn = pHNConn;
  2230. AddRefObj(m_pHNetConn);
  2231. LinkWindow_RegisterClass(); // REVIEW failure here?
  2232. }
  2233. CLanAdvancedPage::~CLanAdvancedPage()
  2234. {
  2235. TraceFileFunc(ttidLanUi);
  2236. if (m_rgPrivateCons)
  2237. {
  2238. for (ULONG i = 0; i < m_cPrivate; i++)
  2239. {
  2240. ReleaseObj(m_rgPrivateCons[i]);
  2241. }
  2242. CoTaskMemFree(m_rgPrivateCons);
  2243. }
  2244. ReleaseObj(m_pHNetCfgMgr);
  2245. ReleaseObj(m_pHNetIcsSettings);
  2246. ReleaseObj(m_pHNetConn);
  2247. ReleaseObj(m_pOldSharedConnection);
  2248. LinkWindow_UnregisterClass(_Module.GetResourceInstance());
  2249. }
  2250. // util function used below
  2251. static BOOL IsConnectionIncomingOnly (INetConnection * pNC)
  2252. {
  2253. // Kludge Alert!!!!
  2254. // this #@$% camera doesn't have the right characteristics,
  2255. // so I'm checking by device name
  2256. BOOL b = FALSE;
  2257. DWORD dwCharacteristics = 0;
  2258. NETCON_PROPERTIES * pProps = NULL;
  2259. HRESULT hr = pNC->GetProperties (&pProps);
  2260. if (pProps) {
  2261. dwCharacteristics = pProps->dwCharacter;
  2262. if (!wcscmp (pProps->pszwDeviceName, L"Microsoft TV/Video Connection"))
  2263. b = TRUE;
  2264. NcFreeNetconProperties (pProps);
  2265. }
  2266. if (b)
  2267. return TRUE;
  2268. return (dwCharacteristics & NCCF_INCOMING_ONLY) ? TRUE : FALSE;
  2269. }
  2270. //+---------------------------------------------------------------------------
  2271. //
  2272. // Member: CLanAdvancedPage::OnInitDialog
  2273. //
  2274. // Purpose: Handles the WM_INITDIALOG message
  2275. //
  2276. // Arguments:
  2277. // uMsg []
  2278. // wParam []
  2279. // lParam []
  2280. // bHandled []
  2281. //
  2282. // Returns: TRUE
  2283. //
  2284. // Author: aboladeg 14 May 1998
  2285. //
  2286. // Notes:
  2287. //
  2288. LRESULT CLanAdvancedPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  2289. LPARAM lParam, BOOL& bHandled)
  2290. {
  2291. TraceFileFunc(ttidLanUi);
  2292. LPWSTR pszw;
  2293. HRESULT hr;
  2294. // init firewall section
  2295. if ( IsHNetAllowed(NCPERM_PersonalFirewallConfig) && FALSE == m_fICSPrivate )
  2296. {
  2297. CheckDlgButton(IDC_CHK_Firewall, m_fFirewalled);
  2298. m_fShowDisableFirewallWarning = TRUE; // TODO check registry
  2299. HKEY hFirewallKey;
  2300. if(SUCCEEDED(HrRegOpenKeyEx(HKEY_CURRENT_USER, g_pszFirewallRegKey, KEY_QUERY_VALUE, &hFirewallKey)))
  2301. {
  2302. DWORD dwValue;
  2303. DWORD dwType;
  2304. DWORD dwSize = sizeof(dwValue);
  2305. if(ERROR_SUCCESS == RegQueryValueEx(hFirewallKey, g_pszDisableFirewallWarningValue, NULL, &dwType, reinterpret_cast<BYTE*>(&dwValue), &dwSize))
  2306. {
  2307. if(REG_DWORD == dwType && TRUE == dwValue)
  2308. {
  2309. m_fShowDisableFirewallWarning = FALSE;
  2310. }
  2311. }
  2312. RegCloseKey(hFirewallKey);
  2313. }
  2314. }
  2315. else
  2316. {
  2317. ::EnableWindow(GetDlgItem(IDC_CHK_Firewall), FALSE);
  2318. }
  2319. // The appearance of the dialog depends on how many LAN connections
  2320. // we have other than the current one. If we have only one,
  2321. // then we just show a checkbox. Otherwise, we display
  2322. // (a) a drop-list of LAN connections if 'm_pconn' is not shared, or
  2323. // (b) a disabled edit-box showing the private LAN connection
  2324. // if 'm_pconn' is shared.
  2325. //
  2326. BOOL fPolicyAllowsSharing = IsHNetAllowed(NCPERM_ShowSharedAccessUi);
  2327. if (m_cPrivate == 0)
  2328. {
  2329. // if the have no private adapters, hide all ICS stuff
  2330. ::ShowWindow(GetDlgItem(IDC_GB_Shared), SW_HIDE);
  2331. ::ShowWindow(GetDlgItem(IDC_CHK_Shared), SW_HIDE);
  2332. ::ShowWindow(GetDlgItem(IDC_CHK_BeaconControl), SW_HIDE);
  2333. ::ShowWindow(GetDlgItem(IDC_ST_ICSLINK), SW_HIDE);
  2334. }
  2335. else if (IsConnectionIncomingOnly (m_pconn)) {
  2336. // bug 281820: disable group box if NCCF_INCOMING_ONLY bit is set
  2337. m_fShared = FALSE;
  2338. ::EnableWindow(GetDlgItem(IDC_GB_Shared), FALSE);
  2339. ::ShowWindow (GetDlgItem(IDC_GB_Shared), SW_HIDE);
  2340. ::EnableWindow(GetDlgItem(IDC_CHK_Shared), FALSE);
  2341. ::ShowWindow (GetDlgItem(IDC_CHK_Shared), SW_HIDE);
  2342. ::EnableWindow(GetDlgItem(IDC_CHK_BeaconControl), FALSE);
  2343. ::ShowWindow (GetDlgItem(IDC_CHK_BeaconControl), SW_HIDE);
  2344. ::EnableWindow(GetDlgItem(IDC_ST_ICSLINK), FALSE);
  2345. ::ShowWindow (GetDlgItem(IDC_ST_ICSLINK), SW_HIDE);
  2346. }
  2347. else if(FALSE == fPolicyAllowsSharing)
  2348. {
  2349. // if policy disables ICS just gray the checkbox
  2350. ::EnableWindow(GetDlgItem(IDC_CHK_Shared), FALSE);
  2351. ::EnableWindow(GetDlgItem(IDC_CHK_BeaconControl), FALSE);
  2352. }
  2353. else if(m_cPrivate > 1)
  2354. {
  2355. // Show a drop-list of LAN connections or a disabled edit-box
  2356. // depending on whether 'm_pconn' is shared, in both cases
  2357. // hiding the smaller groupbox and showing the larger one
  2358. // along with the 'private LAN' label.
  2359. //
  2360. ::ShowWindow(GetDlgItem(IDC_GB_Shared), SW_HIDE);
  2361. ::ShowWindow(GetDlgItem(IDC_GB_PrivateLan), SW_SHOW);
  2362. // show the text label
  2363. ::ShowWindow(GetDlgItem(IDC_ST_HomeNetworkLabel), SW_SHOW);
  2364. ::EnableWindow(GetDlgItem(IDC_ST_HomeNetworkLabel), TRUE);
  2365. // move the beaconcontrol checkbox down
  2366. RECT SourceRect;
  2367. RECT TargetRect;
  2368. ::GetWindowRect(GetDlgItem(IDC_CHK_BeaconControl), &SourceRect);
  2369. ::GetWindowRect(GetDlgItem(IDC_ST_PositionBar), &TargetRect);
  2370. LONG lDelta = TargetRect.top - SourceRect.top; // how far we need to move the controls down
  2371. ::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&SourceRect, 2); // convert screen to client
  2372. ::SetWindowPos( GetDlgItem(IDC_CHK_BeaconControl), NULL, SourceRect.left, SourceRect.top + lDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
  2373. ::GetWindowRect(GetDlgItem(IDC_ST_ICSLINK), &SourceRect);
  2374. ::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&SourceRect, 2); // convert screen to client
  2375. ::SetWindowPos(GetDlgItem(IDC_ST_ICSLINK), NULL, SourceRect.left, SourceRect.top + lDelta, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
  2376. if (m_fShared && !m_fResetPrivateAdapter)
  2377. {
  2378. ::ShowWindow(GetDlgItem(IDC_EDT_PrivateLan), SW_SHOW);
  2379. // Display the private LAN in the editbox
  2380. //
  2381. hr = m_rgPrivateCons[m_lxCurrentPrivate]->GetName(&pszw);
  2382. if (SUCCEEDED(hr))
  2383. {
  2384. SetDlgItemText(IDC_EDT_PrivateLan, pszw);
  2385. CoTaskMemFree(pszw);
  2386. }
  2387. }
  2388. else
  2389. {
  2390. // show and configure the dropdown
  2391. HWND hwndCb = GetDlgItem(IDC_CB_PrivateLan);
  2392. INT i, item;
  2393. ::ShowWindow(hwndCb, SW_SHOW);
  2394. // Add the bogus entry to the combobox
  2395. pszw = const_cast<LPWSTR>(SzLoadIds(IDS_SHAREDACCESS_SELECTADAPTER));
  2396. Assert(pszw);
  2397. item = ComboBox_AddString(hwndCb, pszw);
  2398. if (item != CB_ERR && item != CB_ERRSPACE)
  2399. {
  2400. ComboBox_SetItemData(hwndCb, item, NULL); // ensure item data is null for validation purposes
  2401. }
  2402. // Fill the combobox with LAN names
  2403. //
  2404. for (i = 0; i < (INT)m_cPrivate; i++)
  2405. {
  2406. hr = m_rgPrivateCons[i]->GetName(&pszw);
  2407. if (SUCCEEDED(hr))
  2408. {
  2409. item = ComboBox_AddString(hwndCb, pszw);
  2410. if (item != CB_ERR && item != CB_ERRSPACE)
  2411. {
  2412. ComboBox_SetItemData(
  2413. hwndCb, item, m_rgPrivateCons[i] );
  2414. }
  2415. CoTaskMemFree(pszw);
  2416. }
  2417. }
  2418. ComboBox_SetCurSel( hwndCb, 0 );
  2419. }
  2420. }
  2421. ::EnableWindow(GetDlgItem(IDC_PSB_Settings), m_fShared || m_fFirewalled);
  2422. BOOL fBeaconControl = TRUE;
  2423. HKEY hKey;
  2424. DWORD dwError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGKEY_SHAREDACCESSCLIENTKEYPATH, 0, KEY_QUERY_VALUE, &hKey);
  2425. if(ERROR_SUCCESS == dwError) // if this fails we assume it is on, set the box, and commit on apply
  2426. {
  2427. DWORD dwType;
  2428. DWORD dwData = 0;
  2429. DWORD dwSize = sizeof(dwData);
  2430. dwError = RegQueryValueEx(hKey, REGVAL_SHAREDACCESSCLIENTENABLECONTROL, 0, &dwType, reinterpret_cast<LPBYTE>(&dwData), &dwSize);
  2431. if(ERROR_SUCCESS == dwError && REG_DWORD == dwType && 0 == dwData)
  2432. {
  2433. fBeaconControl = FALSE;
  2434. }
  2435. RegCloseKey(hKey);
  2436. }
  2437. CheckDlgButton(IDC_CHK_Shared, m_fShared);
  2438. CheckDlgButton(IDC_CHK_BeaconControl, fBeaconControl);
  2439. ::EnableWindow(GetDlgItem(IDC_CHK_BeaconControl), m_fShared && fPolicyAllowsSharing);
  2440. //if the machine is personal or workstation, show the HNW link
  2441. OSVERSIONINFOEXW verInfo = {0};
  2442. ULONGLONG ConditionMask = 0;
  2443. verInfo.dwOSVersionInfoSize = sizeof(verInfo);
  2444. verInfo.wProductType = VER_NT_WORKSTATION;
  2445. VER_SET_CONDITION(ConditionMask, VER_PRODUCT_TYPE, VER_LESS_EQUAL);
  2446. if(0 != VerifyVersionInfo(&verInfo, VER_PRODUCT_TYPE, ConditionMask))
  2447. {
  2448. // but only if not on a domain
  2449. LPWSTR pszNameBuffer;
  2450. NETSETUP_JOIN_STATUS BufferType;
  2451. if(NERR_Success == NetGetJoinInformation(NULL, &pszNameBuffer, &BufferType))
  2452. {
  2453. NetApiBufferFree(pszNameBuffer);
  2454. if(NetSetupDomainName != BufferType)
  2455. {
  2456. ::ShowWindow(GetDlgItem(IDC_ST_HNWLINK), SW_SHOW);
  2457. }
  2458. }
  2459. }
  2460. //
  2461. // Making sure that Beacon checkbox is enabled only for
  2462. // Pro and Per Types of the OS.
  2463. //
  2464. VER_SET_CONDITION(ConditionMask, VER_PRODUCT_TYPE, VER_EQUAL);
  2465. if ( 0 == VerifyVersionInfo(&verInfo, VER_PRODUCT_TYPE, ConditionMask) &&
  2466. ERROR_OLD_WIN_VERSION == GetLastError() )
  2467. {
  2468. ::ShowWindow(GetDlgItem(IDC_CHK_BeaconControl), SW_HIDE);
  2469. }
  2470. return TRUE;
  2471. }
  2472. //+---------------------------------------------------------------------------
  2473. //
  2474. // Member: CLanAdvancedPage::OnContextMenu
  2475. //
  2476. // Purpose: When right click a control, bring up help
  2477. //
  2478. // Arguments: Standard command parameters
  2479. //
  2480. // Returns: Standard return
  2481. //
  2482. LRESULT
  2483. CLanAdvancedPage::OnContextMenu(UINT uMsg,
  2484. WPARAM wParam,
  2485. LPARAM lParam,
  2486. BOOL& fHandled)
  2487. {
  2488. TraceFileFunc(ttidLanUi);
  2489. if (m_adwHelpIDs != NULL)
  2490. {
  2491. ::WinHelp(m_hWnd,
  2492. c_szNetCfgHelpFile,
  2493. HELP_CONTEXTMENU,
  2494. (ULONG_PTR)m_adwHelpIDs);
  2495. }
  2496. return 0;
  2497. }
  2498. //+---------------------------------------------------------------------------
  2499. //
  2500. // Member: CLanAdvancedPage::OnHelp
  2501. //
  2502. // Purpose: When drag context help icon over a control, bring up help
  2503. //
  2504. // Arguments: Standard command parameters
  2505. //
  2506. // Returns: Standard return
  2507. //
  2508. LRESULT
  2509. CLanAdvancedPage::OnHelp(UINT uMsg,
  2510. WPARAM wParam,
  2511. LPARAM lParam,
  2512. BOOL& fHandled)
  2513. {
  2514. TraceFileFunc(ttidLanUi);
  2515. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  2516. Assert(lphi);
  2517. if ((m_adwHelpIDs != NULL) && (HELPINFO_WINDOW == lphi->iContextType))
  2518. {
  2519. ::WinHelp(static_cast<HWND>(lphi->hItemHandle),
  2520. c_szNetCfgHelpFile,
  2521. HELP_WM_HELP,
  2522. (ULONG_PTR)m_adwHelpIDs);
  2523. }
  2524. return 0;
  2525. }
  2526. //+---------------------------------------------------------------------------
  2527. //
  2528. // Member: CLanAdvancedPage::OnApply
  2529. //
  2530. // Purpose: Called when the 'Shared Access' page is applied
  2531. //
  2532. // Arguments:
  2533. // idCtrl []
  2534. // pnmh []
  2535. // bHandled []
  2536. //
  2537. // Returns:
  2538. //
  2539. // Author: aboladeg 14 May 1998
  2540. //
  2541. // Notes:
  2542. //
  2543. LRESULT CLanAdvancedPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  2544. {
  2545. TraceFileFunc(ttidLanUi);
  2546. HRESULT hr = S_OK;
  2547. IHNetIcsPrivateConnection *pIcsPrivate;
  2548. IHNetConnection *pPrivateConn;
  2549. IHNetIcsPublicConnection *pIcsPublic;
  2550. ULONG ulcPub, ulcPvt;
  2551. BOOLEAN fPrivateConfigured = FALSE;
  2552. BOOLEAN fConflictDialogDisplayed = FALSE;
  2553. HNET_CONN_PROPERTIES *pProps;
  2554. if (!!m_fFirewalled != !!IsDlgButtonChecked(IDC_CHK_Firewall))
  2555. {
  2556. IHNetFirewalledConnection *pFWConn;
  2557. if (m_fFirewalled)
  2558. {
  2559. //
  2560. // Obtain our firewalled connection interface
  2561. //
  2562. hr = m_pHNetConn->GetControlInterface(
  2563. __uuidof(IHNetFirewalledConnection),
  2564. reinterpret_cast<void**>(&pFWConn)
  2565. );
  2566. if (SUCCEEDED(hr))
  2567. {
  2568. hr = pFWConn->Unfirewall();
  2569. ReleaseObj(pFWConn);
  2570. if (SUCCEEDED(hr))
  2571. {
  2572. m_fFirewalled = FALSE;
  2573. }
  2574. }
  2575. }
  2576. else
  2577. {
  2578. hr = m_pHNetConn->Firewall(&pFWConn);
  2579. if (SUCCEEDED(hr))
  2580. {
  2581. ReleaseObj(pFWConn);
  2582. m_fFirewalled = TRUE;
  2583. }
  2584. }
  2585. if (!SUCCEEDED(hr))
  2586. {
  2587. if (HRESULT_CODE(hr) == ERROR_SHARING_RRAS_CONFLICT)
  2588. {
  2589. fConflictDialogDisplayed = TRUE;
  2590. NcMsgBox(_Module.GetResourceInstance(),
  2591. m_hWnd,
  2592. IDS_LAN_CAPTION,
  2593. IDS_LANUI_SHARING_CONFLICT,
  2594. MB_ICONINFORMATION | MB_OK);
  2595. }
  2596. else
  2597. {
  2598. NcRasMsgBoxWithErrorText (HRESULT_CODE(hr),
  2599. _Module.GetResourceInstance(), m_hWnd,
  2600. IDS_LANUI_ERROR_CAPTION, IDS_TEXT_WITH_RAS_ERROR,
  2601. m_fFirewalled ? IDS_LAN_UNSHARE_FAILED : IDS_LAN_SHARE_FAILED,
  2602. MB_OK | MB_ICONEXCLAMATION );
  2603. }
  2604. }
  2605. }
  2606. if (!!m_fShared != !!IsDlgButtonChecked(IDC_CHK_Shared))
  2607. {
  2608. if (m_fShared)
  2609. {
  2610. //
  2611. // Instead of dealing w/ the public and private connection
  2612. // individually, we simply just diasable all sharing
  2613. //
  2614. hr = m_pHNetIcsSettings->DisableIcs(&ulcPub, &ulcPvt);
  2615. if (SUCCEEDED(hr))
  2616. {
  2617. m_fShared = FALSE;
  2618. }
  2619. }
  2620. else
  2621. {
  2622. if (m_cPrivate > 1)
  2623. {
  2624. HWND hWndCb = GetDlgItem(IDC_CB_PrivateLan);
  2625. INT item = ComboBox_GetCurSel(hWndCb);
  2626. if (item != CB_ERR)
  2627. {
  2628. pPrivateConn =
  2629. (IHNetConnection*)ComboBox_GetItemData(hWndCb, item);
  2630. }
  2631. }
  2632. else
  2633. {
  2634. ASSERT(NULL != m_rgPrivateCons);
  2635. pPrivateConn = m_rgPrivateCons[0];
  2636. }
  2637. //
  2638. // Check to see if the selected private connection is already
  2639. // configured as such.
  2640. //
  2641. if (SUCCEEDED(pPrivateConn->GetProperties(&pProps)))
  2642. {
  2643. fPrivateConfigured = pProps->fIcsPrivate;
  2644. CoTaskMemFree(pProps);
  2645. }
  2646. if (m_fOtherShared)
  2647. {
  2648. if (fPrivateConfigured)
  2649. {
  2650. //
  2651. // Unshare old public connection only. Leaving the
  2652. // private connection as-is prevents a lot of
  2653. // useless work.
  2654. //
  2655. ASSERT(NULL != m_pOldSharedConnection);
  2656. hr = m_pOldSharedConnection->Unshare();
  2657. }
  2658. else
  2659. {
  2660. //
  2661. // We need to configure a new private connection, so
  2662. // just wipe out the old configuration.
  2663. //
  2664. hr = m_pHNetIcsSettings->DisableIcs(&ulcPub, &ulcPvt);
  2665. }
  2666. }
  2667. if (SUCCEEDED(hr))
  2668. {
  2669. hr = m_pHNetConn->SharePublic(&pIcsPublic);
  2670. if (SUCCEEDED(hr))
  2671. {
  2672. if (!fPrivateConfigured)
  2673. {
  2674. hr = pPrivateConn->SharePrivate(&pIcsPrivate);
  2675. if (SUCCEEDED(hr))
  2676. {
  2677. ReleaseObj(pIcsPrivate);
  2678. m_fShared = TRUE;
  2679. }
  2680. else
  2681. {
  2682. pIcsPublic->Unshare();
  2683. }
  2684. }
  2685. else
  2686. {
  2687. m_fShared = TRUE;
  2688. }
  2689. ReleaseObj(pIcsPublic);
  2690. }
  2691. }
  2692. }
  2693. if (!SUCCEEDED(hr))
  2694. {
  2695. if (HRESULT_CODE(hr) == ERROR_SHARING_RRAS_CONFLICT)
  2696. {
  2697. if (!fConflictDialogDisplayed)
  2698. {
  2699. NcMsgBox(_Module.GetResourceInstance(),
  2700. m_hWnd,
  2701. IDS_LAN_CAPTION,
  2702. IDS_LANUI_SHARING_CONFLICT,
  2703. MB_ICONINFORMATION | MB_OK);
  2704. }
  2705. }
  2706. else
  2707. {
  2708. NcRasMsgBoxWithErrorText (HRESULT_CODE(hr),
  2709. _Module.GetResourceInstance(), m_hWnd,
  2710. IDS_LANUI_ERROR_CAPTION, IDS_TEXT_WITH_RAS_ERROR,
  2711. m_fShared ? IDS_LAN_UNSHARE_FAILED : IDS_LAN_SHARE_FAILED,
  2712. MB_OK | MB_ICONEXCLAMATION );
  2713. }
  2714. }
  2715. }
  2716. else if (m_fResetPrivateAdapter && m_cPrivate)
  2717. {
  2718. if (m_cPrivate > 1)
  2719. {
  2720. HWND hWndCb = GetDlgItem(IDC_CB_PrivateLan);
  2721. INT item = ComboBox_GetCurSel(hWndCb);
  2722. if (item != CB_ERR)
  2723. {
  2724. pPrivateConn =
  2725. (IHNetConnection*)ComboBox_GetItemData(hWndCb, item);
  2726. }
  2727. }
  2728. else
  2729. {
  2730. ASSERT(NULL != m_rgPrivateCons);
  2731. pPrivateConn = m_rgPrivateCons[0];
  2732. }
  2733. hr = pPrivateConn->SharePrivate(&pIcsPrivate);
  2734. if (SUCCEEDED(hr))
  2735. {
  2736. ReleaseObj(pIcsPrivate);
  2737. }
  2738. else
  2739. {
  2740. HRESULT hr2 = m_pHNetIcsSettings->DisableIcs(&ulcPub, &ulcPvt);
  2741. if (SUCCEEDED(hr2))
  2742. {
  2743. m_fShared = FALSE;
  2744. }
  2745. NcRasMsgBoxWithErrorText (HRESULT_CODE(hr),
  2746. _Module.GetResourceInstance(), m_hWnd,
  2747. IDS_LANUI_ERROR_CAPTION, IDS_TEXT_WITH_RAS_ERROR,
  2748. m_fShared ? IDS_LAN_UNSHARE_FAILED : IDS_LAN_SHARE_FAILED,
  2749. MB_OK | MB_ICONEXCLAMATION );
  2750. }
  2751. }
  2752. HKEY hKey;
  2753. if(ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, REGKEY_SHAREDACCESSCLIENTKEYPATH, 0, NULL, 0, KEY_SET_VALUE, NULL, &hKey, NULL))
  2754. {
  2755. DWORD dwData = BST_CHECKED == IsDlgButtonChecked(IDC_CHK_BeaconControl);
  2756. RegSetValueEx(hKey, REGVAL_SHAREDACCESSCLIENTENABLECONTROL, 0, REG_DWORD, reinterpret_cast<LPBYTE>(&dwData), sizeof(dwData));
  2757. RegCloseKey(hKey);
  2758. }
  2759. TraceError("CLanAdvancedPage::OnApply", hr);
  2760. //
  2761. // We always need to return a success code here. If we return a failure
  2762. // code the dialog won't go away, allowing the user to click "OK" a
  2763. // second time. This second call will result in problems w/ other
  2764. // property sheets (e.g., CLanNetPage), as they aren't expecting this
  2765. // second (non-reentrant) call to OnApply.
  2766. //
  2767. return PSNRET_NOERROR;
  2768. }
  2769. //+---------------------------------------------------------------------------
  2770. //
  2771. // Member: CLanAdvancedPage::OnCancel
  2772. //
  2773. // Purpose: Called when the 'Shared Access' page is cancelled.
  2774. //
  2775. // Arguments:
  2776. // idCtrl []
  2777. // pnmh []
  2778. // bHandled []
  2779. //
  2780. // Returns:
  2781. //
  2782. // Author: aboladeg 14 May 1998
  2783. //
  2784. // Notes:
  2785. //
  2786. LRESULT CLanAdvancedPage::OnCancel(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  2787. {
  2788. TraceFileFunc(ttidLanUi);
  2789. return LresFromHr(S_OK);
  2790. }
  2791. //+---------------------------------------------------------------------------
  2792. //
  2793. // Member: CLanAdvancedPage::OnKillActive
  2794. //
  2795. // Purpose: Called when the 'Shared Access' page is deactivated,
  2796. // or applied.
  2797. //
  2798. // Arguments:
  2799. // idCtrl []
  2800. // pnmh []
  2801. // bHandled []
  2802. //
  2803. // Returns:
  2804. //
  2805. // Author: aboladeg 6 July 1998
  2806. //
  2807. // Notes:
  2808. //
  2809. LRESULT CLanAdvancedPage::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  2810. {
  2811. TraceFileFunc(ttidLanUi);
  2812. //
  2813. // m_fOtherShared will be set to true in OnShared if we're switching the
  2814. // shared connection. Since we've already displayed a warning for
  2815. // switching, we don't need to display another here.
  2816. //
  2817. if (IsDlgButtonChecked(IDC_CHK_Shared) && (!m_fShared || (m_fResetPrivateAdapter && 0 != m_cPrivate)))
  2818. {
  2819. IHNetConnection* pPrivateConn = NULL;
  2820. if(1 < m_cPrivate) // if the combobox is showing make sure they selected a valid adapter
  2821. {
  2822. HWND hwndCb = GetDlgItem(IDC_CB_PrivateLan);
  2823. INT item = ComboBox_GetCurSel(hwndCb);
  2824. if (item != CB_ERR)
  2825. {
  2826. pPrivateConn = reinterpret_cast<IHNetConnection*>(ComboBox_GetItemData(hwndCb, item));
  2827. }
  2828. }
  2829. else
  2830. {
  2831. pPrivateConn = m_rgPrivateCons[0];
  2832. }
  2833. if(NULL == pPrivateConn)
  2834. {
  2835. Assert(1 < m_cPrivate);
  2836. NcMsgBox(_Module.GetResourceInstance(), m_hWnd, IDS_LAN_CAPTION,
  2837. IDS_SHAREDACCESS_SELECTADAPTERERROR, MB_OK | MB_ICONWARNING);
  2838. SetWindowLong(DWLP_MSGRESULT, PSNRET_INVALID);
  2839. return TRUE;
  2840. }
  2841. if(!m_fOtherShared && FALSE == IsAdapterDHCPEnabled(pPrivateConn))
  2842. {
  2843. int nRet = NcMsgBox(
  2844. _Module.GetResourceInstance(), m_hWnd, IDS_LAN_CAPTION,
  2845. IDS_LAN_ENABLE_SHARED_ACCESS, MB_ICONINFORMATION|MB_YESNO);
  2846. if (nRet == IDNO)
  2847. {
  2848. SetWindowLong(DWLP_MSGRESULT, TRUE);
  2849. return TRUE;
  2850. }
  2851. }
  2852. }
  2853. if (TRUE == m_fFirewalled && TRUE == m_fShowDisableFirewallWarning && BST_UNCHECKED == IsDlgButtonChecked(IDC_CHK_Firewall))
  2854. {
  2855. INT_PTR nDialogResult;
  2856. m_fShowDisableFirewallWarning = FALSE;
  2857. nDialogResult = DialogBox(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_DISABLEFIREWALLWARNING), m_hWnd, DisableFirewallWarningDlgProc);
  2858. if(-1 != nDialogResult && IDYES != nDialogResult)
  2859. {
  2860. CheckDlgButton(IDC_CHK_Firewall, BST_CHECKED);
  2861. ::EnableWindow(
  2862. GetDlgItem(IDC_PSB_Settings),
  2863. BST_CHECKED == IsDlgButtonChecked(IDC_CHK_Firewall) || BST_CHECKED == IsDlgButtonChecked(IDC_CHK_Shared)
  2864. );
  2865. }
  2866. }
  2867. return FALSE;
  2868. }
  2869. //+---------------------------------------------------------------------------
  2870. //
  2871. // Member: CLanAdvancedPage::OnShared
  2872. //
  2873. // Purpose: Handles the clicking of the Shared button
  2874. //
  2875. // Arguments:
  2876. // wNotifyCode []
  2877. // wID []
  2878. // hWndCtl []
  2879. // bHandled []
  2880. //
  2881. // Returns:
  2882. //
  2883. // Author: aboladeg 23 May 1998
  2884. //
  2885. // Notes:
  2886. //
  2887. LRESULT CLanAdvancedPage::OnShared(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  2888. BOOL& bHandled)
  2889. {
  2890. TraceFileFunc(ttidLanUi);
  2891. BOOL fShared = IsDlgButtonChecked(IDC_CHK_Shared);
  2892. if (!m_fShared && fShared)
  2893. {
  2894. //
  2895. // Check to see if the user is changing the shared connection
  2896. //
  2897. HRESULT hr = S_OK;
  2898. IHNetIcsPublicConnection* pOldIcsConn;
  2899. IHNetConnection* pOldConn;
  2900. PWSTR pszwOld;
  2901. NETCON_PROPERTIES* pProps;
  2902. IEnumHNetIcsPublicConnections *pEnum;
  2903. hr = m_pHNetIcsSettings->EnumIcsPublicConnections(&pEnum);
  2904. if (SUCCEEDED(hr))
  2905. {
  2906. ULONG ulCount;
  2907. hr = pEnum->Next(1, &pOldIcsConn, &ulCount);
  2908. if (SUCCEEDED(hr) && 1 == ulCount)
  2909. {
  2910. hr = pOldIcsConn->QueryInterface(
  2911. __uuidof(pOldConn),
  2912. reinterpret_cast<void**>(&pOldConn)
  2913. );
  2914. if (SUCCEEDED(hr))
  2915. {
  2916. hr = pOldConn->GetName(&pszwOld);
  2917. ReleaseObj(pOldConn);
  2918. //
  2919. // Transfer reference for old shared connection
  2920. //
  2921. m_pOldSharedConnection = pOldIcsConn;
  2922. //
  2923. // Even if we weren't able to obtain the name of the
  2924. // old shared connection, we need to note that such
  2925. // a connection exists. (This situation will arise if
  2926. // the old shared connection has been removed from the
  2927. // system.)
  2928. //
  2929. m_fOtherShared = TRUE;
  2930. }
  2931. else
  2932. {
  2933. ReleaseObj(pOldIcsConn);
  2934. }
  2935. }
  2936. else
  2937. {
  2938. m_fOtherShared = FALSE;
  2939. }
  2940. ReleaseObj(pEnum);
  2941. }
  2942. if (SUCCEEDED(hr) && m_fOtherShared)
  2943. {
  2944. hr = m_pconn->GetProperties(&pProps);
  2945. if (SUCCEEDED(hr))
  2946. {
  2947. NcMsgBox(
  2948. _Module.GetResourceInstance(), m_hWnd, IDS_LANUI_ERROR_CAPTION,
  2949. IDS_LAN_CHANGE_SHARED_CONNECTION, MB_ICONINFORMATION|MB_OK,
  2950. pszwOld, pProps->pszwName );
  2951. FreeNetconProperties(pProps);
  2952. }
  2953. CoTaskMemFree(pszwOld);
  2954. }
  2955. }
  2956. ::EnableWindow(GetDlgItem(IDC_PSB_Settings), fShared || BST_CHECKED == IsDlgButtonChecked(IDC_CHK_Firewall));
  2957. ::EnableWindow(GetDlgItem(IDC_CHK_BeaconControl), fShared);
  2958. return LresFromHr(S_OK);
  2959. }
  2960. //+---------------------------------------------------------------------------
  2961. //
  2962. // Member: CLanAdvancedPage::OnFirewall
  2963. //
  2964. // Purpose: Handles the clicking of the Firewall checkbox
  2965. //
  2966. // Arguments:
  2967. // wNotifyCode []
  2968. // wID []
  2969. // hWndCtl []
  2970. // bHandled []
  2971. //
  2972. // Returns:
  2973. //
  2974. // Author: jonburs 6 Oct 1999
  2975. //
  2976. // Notes:
  2977. //
  2978. LRESULT CLanAdvancedPage::OnFirewall(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  2979. BOOL& bHandled)
  2980. {
  2981. TraceFileFunc(ttidLanUi);
  2982. if (BST_CHECKED == IsDlgButtonChecked(IDC_CHK_Firewall)) {
  2983. // if checked, see if local machine is a node in a cluster
  2984. DWORD dwClusterState = 0;
  2985. GetNodeClusterState (NULL, &dwClusterState);
  2986. if ((dwClusterState == ClusterStateNotRunning) ||
  2987. (dwClusterState == ClusterStateRunning ) ){
  2988. // pop up warning
  2989. ::MessageBox (m_hWnd,
  2990. SzLoadIds (IDS_CLUSTERING_CONFLICT_WARNING),
  2991. SzLoadIds (IDS_LANUI_ERROR_CAPTION),
  2992. MB_OK | MB_ICONWARNING);
  2993. }
  2994. }
  2995. ::EnableWindow(
  2996. GetDlgItem(IDC_PSB_Settings),
  2997. BST_CHECKED == IsDlgButtonChecked(IDC_CHK_Firewall) || BST_CHECKED == IsDlgButtonChecked(IDC_CHK_Shared)
  2998. );
  2999. return LresFromHr(S_OK);
  3000. }
  3001. //+---------------------------------------------------------------------------
  3002. //
  3003. // Member: CLanAdvancedPage::OnSettings
  3004. //
  3005. // Purpose: Handles the clicking of the Settings button
  3006. //
  3007. // Arguments:
  3008. // wNotifyCode []
  3009. // wID []
  3010. // hWndCtl []
  3011. // bHandled []
  3012. //
  3013. // Returns:
  3014. //
  3015. // Author: aboladeg 25 Oct 1998
  3016. //
  3017. // Notes:
  3018. //
  3019. LRESULT CLanAdvancedPage::OnSettings(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  3020. BOOL& bHandled)
  3021. {
  3022. DWORD dwLastError = NOERROR;
  3023. TraceFileFunc(ttidLanUi);
  3024. HINSTANCE hinstance = LoadLibrary(TEXT("hnetcfg.dll"));
  3025. if (!hinstance)
  3026. dwLastError = GetLastError();
  3027. else {
  3028. BOOL (APIENTRY *pfnHNetSharingAndFirewallSettingsDlg)(HWND, IHNetCfgMgr*, BOOL, IHNetConnection*);
  3029. pfnHNetSharingAndFirewallSettingsDlg = (BOOL (APIENTRY *)(HWND, IHNetCfgMgr*, BOOL, IHNetConnection*))
  3030. ::GetProcAddress(hinstance, "HNetSharingAndFirewallSettingsDlg");
  3031. if (!pfnHNetSharingAndFirewallSettingsDlg)
  3032. dwLastError = GetLastError();
  3033. else
  3034. pfnHNetSharingAndFirewallSettingsDlg(m_hWnd, m_pHNetCfgMgr, IsDlgButtonChecked(IDC_CHK_Firewall), m_pHNetConn);
  3035. FreeLibrary (hinstance);
  3036. }
  3037. if (dwLastError != NOERROR) {
  3038. LPVOID lpMsgBuf = NULL;
  3039. if (FormatMessage(
  3040. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  3041. FORMAT_MESSAGE_FROM_SYSTEM |
  3042. FORMAT_MESSAGE_IGNORE_INSERTS,
  3043. NULL,
  3044. dwLastError,
  3045. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  3046. (LPTSTR) &lpMsgBuf,
  3047. 0,
  3048. NULL)) {
  3049. // Display the string.
  3050. MessageBox( (LPCTSTR)lpMsgBuf );
  3051. // Free the buffer.
  3052. LocalFree( lpMsgBuf );
  3053. }
  3054. }
  3055. return LresFromHr(S_OK);
  3056. }
  3057. //+---------------------------------------------------------------------------
  3058. //
  3059. // Member: CLanAdvancedPage::OnClick
  3060. //
  3061. // Purpose: Called in response to the NM_CLICK message
  3062. //
  3063. // Arguments:
  3064. // idCtrl []
  3065. // pnmh []
  3066. // fHandled []
  3067. //
  3068. // Returns:
  3069. //
  3070. // Author: kenwic 11 Sep 2000
  3071. //
  3072. // Notes:
  3073. //
  3074. LRESULT CLanAdvancedPage::OnClick(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  3075. {
  3076. TraceFileFunc(ttidLanUi);
  3077. if(IDC_ST_HNWLINK == idCtrl)
  3078. {
  3079. HWND hPropertySheetWindow = GetParent();
  3080. if(NULL != hPropertySheetWindow)
  3081. {
  3082. ShellExecute(NULL,TEXT("open"),TEXT("rundll32"), TEXT("hnetwiz.dll,HomeNetWizardRunDll"),NULL,SW_SHOW);
  3083. ::PostMessage(hPropertySheetWindow, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM) ::GetDlgItem(hPropertySheetWindow, IDCANCEL));
  3084. }
  3085. }
  3086. else if(IDC_ST_ICFLINK == idCtrl || IDC_ST_ICSLINK == idCtrl)
  3087. {
  3088. LPTSTR pszHelpTopic = IDC_ST_ICFLINK == idCtrl ? TEXT("netcfg.chm::/hnw_understanding_firewall.htm") : TEXT("netcfg.chm::/Share_conn_overvw.htm");
  3089. HtmlHelp(NULL, pszHelpTopic, HH_DISPLAY_TOPIC, 0);
  3090. }
  3091. return 0;
  3092. }
  3093. INT_PTR CALLBACK CLanAdvancedPage::DisableFirewallWarningDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3094. {
  3095. TraceFileFunc(ttidLanUi);
  3096. switch(uMsg)
  3097. {
  3098. case WM_COMMAND:
  3099. {
  3100. switch(LOWORD(wParam))
  3101. {
  3102. case IDYES:
  3103. case IDNO:
  3104. if(BST_CHECKED == ::IsDlgButtonChecked(hWnd, IDC_CHK_DISABLEFIREWALLWARNING))
  3105. {
  3106. HKEY hFirewallKey;
  3107. if(SUCCEEDED(HrRegCreateKeyEx(HKEY_CURRENT_USER, g_pszFirewallRegKey, 0, KEY_SET_VALUE, NULL, &hFirewallKey, NULL)))
  3108. {
  3109. DWORD dwValue = TRUE;
  3110. HrRegSetValueEx(hFirewallKey, g_pszDisableFirewallWarningValue, REG_DWORD, reinterpret_cast<CONST BYTE*>(&dwValue), sizeof(dwValue));
  3111. RegCloseKey(hFirewallKey);
  3112. }
  3113. }
  3114. // fallthru
  3115. case IDCANCEL:
  3116. EndDialog(hWnd, LOWORD(wParam));
  3117. break;
  3118. }
  3119. break;
  3120. }
  3121. }
  3122. return FALSE;
  3123. }
  3124. //+---------------------------------------------------------------------------
  3125. //
  3126. // Member: CLanAdvancedPage::IsAdapterDHCPEnabled
  3127. //
  3128. // Purpose: Check if DHCP is set on this adapter
  3129. //
  3130. // Arguments:
  3131. // pConnection: the adapter
  3132. //
  3133. // Returns:
  3134. //
  3135. // Author: kenwic 11 Oct 2000
  3136. //
  3137. // Notes:
  3138. //
  3139. BOOL CLanAdvancedPage::IsAdapterDHCPEnabled(IHNetConnection* pConnection)
  3140. {
  3141. TraceFileFunc(ttidLanUi);
  3142. HRESULT hr;
  3143. BOOL fDHCP = FALSE;
  3144. GUID* pAdapterGuid;
  3145. hr = pConnection->GetGuid(&pAdapterGuid);
  3146. if(SUCCEEDED(hr))
  3147. {
  3148. LPOLESTR pAdapterName;
  3149. hr = StringFromCLSID(*pAdapterGuid, &pAdapterName);
  3150. if(SUCCEEDED(hr))
  3151. {
  3152. SIZE_T Length = wcslen(pAdapterName);
  3153. LPSTR pszAnsiAdapterName = new char[Length + 1];
  3154. if(NULL != pszAnsiAdapterName)
  3155. {
  3156. if(0 != WideCharToMultiByte(CP_ACP, 0, pAdapterName, (int)(Length + 1), pszAnsiAdapterName, (int)(Length + 1), NULL, NULL))
  3157. {
  3158. HMODULE hIpHelper;
  3159. hIpHelper = LoadLibrary(L"iphlpapi");
  3160. if(NULL != hIpHelper)
  3161. {
  3162. DWORD (WINAPI *pGetAdaptersInfo)(PIP_ADAPTER_INFO, PULONG);
  3163. pGetAdaptersInfo = (DWORD (WINAPI*)(PIP_ADAPTER_INFO, PULONG)) GetProcAddress(hIpHelper, "GetAdaptersInfo");
  3164. if(NULL != pGetAdaptersInfo)
  3165. {
  3166. ULONG ulSize = 0;
  3167. if(ERROR_BUFFER_OVERFLOW == pGetAdaptersInfo(NULL, &ulSize))
  3168. {
  3169. BYTE* pInfoArray = new BYTE[ulSize];
  3170. PIP_ADAPTER_INFO pInfo = reinterpret_cast<PIP_ADAPTER_INFO>(pInfoArray);
  3171. if(NULL != pInfo)
  3172. {
  3173. if(ERROR_SUCCESS == pGetAdaptersInfo(pInfo, &ulSize))
  3174. {
  3175. PIP_ADAPTER_INFO pAdapterInfo = pInfo;
  3176. do
  3177. {
  3178. if(0 == lstrcmpA(pszAnsiAdapterName, pAdapterInfo->AdapterName))
  3179. {
  3180. fDHCP = !!pAdapterInfo->DhcpEnabled;
  3181. break;
  3182. }
  3183. } while(NULL != (pAdapterInfo = pAdapterInfo->Next));
  3184. }
  3185. delete [] pInfoArray;
  3186. }
  3187. }
  3188. }
  3189. FreeLibrary(hIpHelper);
  3190. }
  3191. }
  3192. delete [] pszAnsiAdapterName;
  3193. }
  3194. CoTaskMemFree(pAdapterName);
  3195. }
  3196. CoTaskMemFree(pAdapterGuid);
  3197. }
  3198. return fDHCP;
  3199. }
  3200. //
  3201. // CLanAddComponentDlg
  3202. //
  3203. struct ADD_COMPONENT_INFO
  3204. {
  3205. UINT uiIdsName;
  3206. UINT uiIdsDesc;
  3207. const GUID * pguidClass;
  3208. };
  3209. static const ADD_COMPONENT_INFO c_rgaci[] =
  3210. {
  3211. {IDS_LAN_CLIENT, IDS_LAN_CLIENT_DESC, &GUID_DEVCLASS_NETCLIENT},
  3212. {IDS_LAN_SERVICE, IDS_LAN_SERVICE_DESC, &GUID_DEVCLASS_NETSERVICE},
  3213. {IDS_LAN_PROTOCOL, IDS_LAN_PROTOCOL_DESC, &GUID_DEVCLASS_NETTRANS},
  3214. };
  3215. static const INT c_naci = celems(c_rgaci);
  3216. //+---------------------------------------------------------------------------
  3217. //
  3218. // Member: CLanAddComponentDlg::OnInitDialog
  3219. //
  3220. // Purpose: Handles the WM_INITDIALOG message
  3221. //
  3222. // Arguments:
  3223. // uMsg []
  3224. // wParam []
  3225. // lParam []
  3226. // bHandled []
  3227. //
  3228. // Returns:
  3229. //
  3230. // Author: danielwe 29 Oct 1997
  3231. //
  3232. // Notes:
  3233. //
  3234. LRESULT CLanAddComponentDlg::OnInitDialog(UINT uMsg, WPARAM wParam,
  3235. LPARAM lParam, BOOL& bHandled)
  3236. {
  3237. TraceFileFunc(ttidLanUi);
  3238. HRESULT hr = S_OK;
  3239. INT iaci;
  3240. RECT rc;
  3241. LV_COLUMN lvc = {0};
  3242. SP_CLASSIMAGELIST_DATA cid = {0};
  3243. BOOL fValidImages = FALSE;
  3244. m_hwndLV = GetDlgItem(IDC_LVW_Lan_Components);
  3245. // Get the class image list structure
  3246. hr = HrSetupDiGetClassImageList(&cid);
  3247. if (SUCCEEDED(hr))
  3248. {
  3249. ListView_SetImageList(m_hwndLV, ImageList_Duplicate(cid.ImageList),
  3250. LVSIL_SMALL);
  3251. fValidImages = TRUE;
  3252. }
  3253. else
  3254. {
  3255. // Handling failure with fValidImages flag
  3256. hr = S_OK;
  3257. }
  3258. ::GetClientRect(m_hwndLV, &rc);
  3259. lvc.mask = LVCF_FMT | LVCF_WIDTH;
  3260. lvc.fmt = LVCFMT_LEFT;
  3261. lvc.cx = rc.right - GetSystemMetrics(SM_CXVSCROLL);
  3262. ListView_InsertColumn(m_hwndLV, 0, &lvc);
  3263. // For each class, add it to the list
  3264. for (iaci = 0; iaci < c_naci; iaci++)
  3265. {
  3266. LV_ITEM lvi = {0};
  3267. lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_PARAM;
  3268. if (fValidImages)
  3269. {
  3270. // Get the component's class image list index
  3271. hr = HrSetupDiGetClassImageIndex(&cid,
  3272. const_cast<LPGUID>(c_rgaci[iaci].pguidClass),
  3273. &lvi.iImage);
  3274. if (SUCCEEDED(hr))
  3275. {
  3276. lvi.mask |= LVIF_IMAGE;
  3277. }
  3278. }
  3279. // Select the first item
  3280. if (iaci == 0)
  3281. {
  3282. lvi.state = lvi.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  3283. }
  3284. lvi.pszText = const_cast<PWSTR>(SzLoadIds(c_rgaci[iaci].uiIdsName));
  3285. lvi.lParam = reinterpret_cast<LPARAM>(c_rgaci[iaci].pguidClass);
  3286. lvi.iItem = iaci;
  3287. ListView_InsertItem(m_hwndLV, &lvi);
  3288. }
  3289. if (fValidImages)
  3290. {
  3291. (void) HrSetupDiDestroyClassImageList(&cid);
  3292. }
  3293. if (FAILED(hr))
  3294. {
  3295. EndDialog(0);
  3296. }
  3297. TraceError("CLanAddComponentDlg::OnInitDialog", hr);
  3298. return TRUE;
  3299. }
  3300. //+---------------------------------------------------------------------------
  3301. //
  3302. // Member: CLanAddComponentDlg::OnContextMenu
  3303. //
  3304. // Purpose: When right click a control, bring up help
  3305. //
  3306. // Arguments: Standard command parameters
  3307. //
  3308. // Returns: Standard return
  3309. //
  3310. LRESULT
  3311. CLanAddComponentDlg::OnContextMenu(UINT uMsg,
  3312. WPARAM wParam,
  3313. LPARAM lParam,
  3314. BOOL& fHandled)
  3315. {
  3316. TraceFileFunc(ttidLanUi);
  3317. if (m_adwHelpIDs != NULL)
  3318. {
  3319. ::WinHelp(m_hWnd,
  3320. c_szNetCfgHelpFile,
  3321. HELP_CONTEXTMENU,
  3322. (ULONG_PTR)m_adwHelpIDs);
  3323. }
  3324. return 0;
  3325. }
  3326. //+---------------------------------------------------------------------------
  3327. //
  3328. // Member: CLanAddComponentDlg::OnHelp
  3329. //
  3330. // Purpose: When drag context help icon over a control, bring up help
  3331. //
  3332. // Arguments: Standard command parameters
  3333. //
  3334. // Returns: Standard return
  3335. //
  3336. LRESULT
  3337. CLanAddComponentDlg::OnHelp( UINT uMsg,
  3338. WPARAM wParam,
  3339. LPARAM lParam,
  3340. BOOL& fHandled)
  3341. {
  3342. TraceFileFunc(ttidLanUi);
  3343. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  3344. Assert(lphi);
  3345. if ((m_adwHelpIDs != NULL) && (HELPINFO_WINDOW == lphi->iContextType))
  3346. {
  3347. ::WinHelp(static_cast<HWND>(lphi->hItemHandle),
  3348. c_szNetCfgHelpFile,
  3349. HELP_WM_HELP,
  3350. (ULONG_PTR)m_adwHelpIDs);
  3351. }
  3352. return 0;
  3353. }
  3354. //+---------------------------------------------------------------------------
  3355. //
  3356. // Member: CLanAddComponentDlg::OnItemChanged
  3357. //
  3358. // Purpose: Handles the selection changed message for the list view
  3359. //
  3360. // Arguments:
  3361. // idCtrl []
  3362. // pnmh []
  3363. // bHandled []
  3364. //
  3365. // Returns:
  3366. //
  3367. // Author: danielwe 29 Oct 1997
  3368. //
  3369. // Notes:
  3370. //
  3371. LRESULT CLanAddComponentDlg::OnItemChanged(int idCtrl, LPNMHDR pnmh,
  3372. BOOL& bHandled)
  3373. {
  3374. TraceFileFunc(ttidLanUi);
  3375. NM_LISTVIEW * pnmlv = reinterpret_cast<NM_LISTVIEW *>(pnmh);
  3376. HWND hwndButton = GetDlgItem(IDC_PSB_Component_Add);
  3377. Assert(pnmlv);
  3378. // Check if selection changed
  3379. if ((pnmlv->uNewState & LVIS_SELECTED) &&
  3380. (!(pnmlv->uOldState & LVIS_SELECTED)))
  3381. {
  3382. // Update the description if/when selection changes
  3383. SetDlgItemText(IDC_TXT_Component_Desc,
  3384. SzLoadIds(c_rgaci[pnmlv->iItem].uiIdsDesc));
  3385. ::EnableWindow(hwndButton, TRUE);
  3386. }
  3387. else if (!(pnmlv->uNewState & LVIS_SELECTED) &&
  3388. (pnmlv->uOldState & LVIS_SELECTED))
  3389. {
  3390. // Update the description if/when selection changes
  3391. SetDlgItemText(IDC_TXT_Component_Desc, c_szEmpty);
  3392. ::EnableWindow(hwndButton, FALSE);
  3393. }
  3394. return 0;
  3395. }
  3396. //+---------------------------------------------------------------------------
  3397. //
  3398. // Member: CLanAddComponentDlg::OnAdd
  3399. //
  3400. // Purpose: Handles the clicking of the Add button
  3401. //
  3402. // Arguments:
  3403. // wNotifyCode []
  3404. // wID []
  3405. // hWndCtl []
  3406. // bHandled []
  3407. //
  3408. // Returns:
  3409. //
  3410. // Author: danielwe 29 Oct 1997
  3411. //
  3412. // Notes:
  3413. //
  3414. LRESULT CLanAddComponentDlg::OnAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  3415. BOOL& bHandled)
  3416. {
  3417. TraceFileFunc(ttidLanUi);
  3418. HRESULT hr = S_OK;
  3419. INT iIndex;
  3420. INetCfgComponent * pncc = NULL;
  3421. BOOL fCancel = FALSE;
  3422. HWND hwndFocus;
  3423. CWaitCursor wc; // Displays a wait cursor
  3424. // Get the selected item
  3425. iIndex = ListView_GetNextItem(m_hwndLV, -1, LVNI_SELECTED);
  3426. if (iIndex != -1)
  3427. {
  3428. int rgidc[] = {IDC_LVW_Lan_Components, IDC_PSB_Component_Add, IDCANCEL};
  3429. CWaitCursor wc;
  3430. LV_ITEM lvi = {0};
  3431. lvi.mask = LVIF_PARAM;
  3432. lvi.iItem = iIndex;
  3433. ListView_GetItem(m_hwndLV, &lvi);
  3434. // Disable the UI
  3435. //
  3436. hwndFocus = ::GetFocus();
  3437. EnableOrDisableDialogControls (m_hWnd, celems(rgidc), rgidc, FALSE);
  3438. // This is its class GUID.
  3439. //
  3440. Assert (lvi.lParam);
  3441. // Get the setup interface for the class and use it to install
  3442. // a component of the user's selection.
  3443. //
  3444. GUID* pClassGuid = (GUID*)lvi.lParam;
  3445. INetCfgInternalSetup* pInternalSetup;
  3446. hr = m_pnc->QueryInterface (IID_INetCfgInternalSetup,
  3447. (void**)&pInternalSetup);
  3448. if (SUCCEEDED(hr))
  3449. {
  3450. OBO_TOKEN OboToken;
  3451. ZeroMemory (&OboToken, sizeof(OboToken));
  3452. OboToken.Type = OBO_USER;
  3453. hr = pInternalSetup->SelectWithFilterAndInstall(m_hWnd,
  3454. pClassGuid, &OboToken, m_pcfi, &pncc);
  3455. if (HRESULT_FROM_WIN32 (ERROR_CANCELLED) == hr)
  3456. {
  3457. fCancel = TRUE;
  3458. hr = S_FALSE;
  3459. }
  3460. else if (S_OK == hr)
  3461. {
  3462. // Commit the changes
  3463. hr = m_pnc->Apply();
  3464. }
  3465. ReleaseObj(pncc);
  3466. ReleaseObj(pInternalSetup);
  3467. }
  3468. EnableOrDisableDialogControls (m_hWnd, celems(rgidc), rgidc, TRUE);
  3469. ::SetFocus( hwndFocus );
  3470. }
  3471. else
  3472. {
  3473. fCancel = TRUE;
  3474. }
  3475. if (SUCCEEDED(hr) && (NETCFG_S_REBOOT != hr))
  3476. {
  3477. // Make sure S_FALSE doesn't get thru
  3478. hr = S_OK;
  3479. }
  3480. if (!fCancel)
  3481. {
  3482. // Return the installed error code as the result. S_OK means user
  3483. // clicked OK and actually added a component. S_FALSE means they
  3484. // cancelled, otherwise this will return an error code
  3485. EndDialog(static_cast<int>(hr));
  3486. }
  3487. TraceError("CLanAddComponentDlg::OnAdd", hr);
  3488. return 0;
  3489. }
  3490. //+---------------------------------------------------------------------------
  3491. //
  3492. // Member: CLanAddComponentDlg::OnCancel
  3493. //
  3494. // Purpose: Called when the cancel button is pressed.
  3495. //
  3496. // Arguments:
  3497. // wNotifyCode []
  3498. // wID []
  3499. // hWndCtl []
  3500. // bHandled []
  3501. //
  3502. // Returns:
  3503. //
  3504. // Author: danielwe 10 Nov 1997
  3505. //
  3506. // Notes:
  3507. //
  3508. LRESULT CLanAddComponentDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl,
  3509. BOOL& bHandled)
  3510. {
  3511. TraceFileFunc(ttidLanUi);
  3512. HRESULT hr = S_FALSE;
  3513. // Return S_FALSE on cancel
  3514. EndDialog(static_cast<int>(hr));
  3515. return 0;
  3516. }
  3517. LRESULT CLanAddComponentDlg::OnDblClick(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  3518. {
  3519. TraceFileFunc(ttidLanUi);
  3520. return OnAdd(0, 0, NULL, bHandled);
  3521. }
  3522. //
  3523. // CLanSecurityPage
  3524. //
  3525. CLanSecurityPage::CLanSecurityPage(
  3526. IUnknown* punk,
  3527. INetCfg* pnc,
  3528. INetConnection* pconn,
  3529. const DWORD * adwHelpIDs)
  3530. {
  3531. TraceFileFunc(ttidLanUi);
  3532. m_pconn = pconn;
  3533. m_pnc = pnc;
  3534. m_fNetcfgInUse = FALSE;
  3535. m_adwHelpIDs = adwHelpIDs;
  3536. pListEapcfgs = NULL;
  3537. }
  3538. //+---------------------------------------------------------------------------
  3539. //
  3540. // Member: CLanSecurityPage::~CLanSecurityPage
  3541. //
  3542. // Purpose: Destroys the CLanSecurityPage object
  3543. //
  3544. // Arguments:
  3545. // (none)
  3546. //
  3547. // Returns: Nothing
  3548. //
  3549. // Author: sachins
  3550. //
  3551. // Notes:
  3552. //
  3553. CLanSecurityPage::~CLanSecurityPage()
  3554. {
  3555. TraceFileFunc(ttidLanUi);
  3556. }
  3557. //+---------------------------------------------------------------------------
  3558. //
  3559. // Member: CLanSecurityPage::OnInitDialog
  3560. //
  3561. // Purpose: Handles the WM_INITDIALOG message
  3562. //
  3563. // Arguments:
  3564. // uMsg []
  3565. // wParam []
  3566. // lParam []
  3567. // bHandled []
  3568. //
  3569. // Returns: error code
  3570. //
  3571. // Author: sachins
  3572. //
  3573. // Notes:
  3574. //
  3575. LRESULT CLanSecurityPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  3576. LPARAM lParam, BOOL& bHandled)
  3577. {
  3578. TraceFileFunc(ttidLanUi);
  3579. DTLNODE* pOriginalEapcfgNode = NULL;
  3580. WCHAR wszGuid[c_cchGuidWithTerm];
  3581. BYTE *pbData = NULL;
  3582. DWORD cbData = 0;
  3583. EAPOL_INTF_PARAMS EapolIntfParams;
  3584. EAPOL_INTF_STATE EapolIntfState = {0};
  3585. BOOLEAN fFlag = FALSE;
  3586. DWORD dwFlags = 0;
  3587. HRESULT hr = S_OK;
  3588. SetClassLongPtr(m_hWnd, GCLP_HCURSOR, NULL);
  3589. SetClassLongPtr(GetParent(), GCLP_HCURSOR, NULL);
  3590. // Initially disable all the controls
  3591. ::EnableWindow(GetDlgItem(CID_CA_RB_Eap), FALSE);
  3592. ::EnableWindow(GetDlgItem(IDC_TXT_EAP_TYPE), FALSE);
  3593. ::EnableWindow(GetDlgItem(CID_CA_LB_EapPackages), FALSE);
  3594. ::EnableWindow(GetDlgItem(CID_CA_PB_Properties), FALSE);
  3595. ::EnableWindow(GetDlgItem(CID_CA_RB_MachineAuth), FALSE);
  3596. ::EnableWindow(GetDlgItem(CID_CA_RB_GuestAuth), FALSE);
  3597. // Initialize EAP package list
  3598. // Read the EAPCFG information from the registry and find the node
  3599. // selected in the entry, or the default, if none.
  3600. do
  3601. {
  3602. DTLNODE* pNode = NULL;
  3603. TCHAR* pszEncEnabled = NULL;
  3604. DTLNODE* pNodeEap;
  3605. DWORD dwkey = 0;
  3606. NETCON_PROPERTIES* pProps;
  3607. hr = m_pconn->GetProperties(&pProps);
  3608. if (SUCCEEDED(hr))
  3609. {
  3610. if ((::StringFromGUID2(pProps->guidId,
  3611. wszGuid,
  3612. c_cchGuidWithTerm)) == 0)
  3613. {
  3614. TraceTag (ttidLanUi, "Security::OnInitDialog: StringFromGUID2 failed");
  3615. FreeNetconProperties(pProps);
  3616. break;
  3617. }
  3618. FreeNetconProperties(pProps);
  3619. }
  3620. else
  3621. {
  3622. TraceTag (ttidLanUi, "Security::OnInitDialog: GetProperties failed");
  3623. break;
  3624. }
  3625. // Read the state for this interface
  3626. ZeroMemory ((BYTE *)&EapolIntfState, sizeof(EAPOL_INTF_STATE));
  3627. DWORD dwRetCode = NO_ERROR;
  3628. dwRetCode = WZCEapolQueryState (
  3629. NULL,
  3630. wszGuid,
  3631. &EapolIntfState
  3632. );
  3633. if (dwRetCode != NO_ERROR)
  3634. {
  3635. TraceTag (ttidLanUi, "WZCEapolQueryState failed with error %ld",
  3636. dwRetCode);
  3637. // Consider the interface as non-wireless
  3638. }
  3639. // Read the EAP params for this interface
  3640. ZeroMemory ((BYTE *)&EapolIntfParams, sizeof(EAPOL_INTF_PARAMS));
  3641. EapolIntfParams.dwEapFlags = DEFAULT_EAP_STATE;
  3642. EapolIntfParams.dwEapType = DEFAULT_EAP_TYPE;
  3643. hr = HrElGetInterfaceParams (
  3644. wszGuid,
  3645. &EapolIntfParams
  3646. );
  3647. if (FAILED (hr))
  3648. {
  3649. TraceTag (ttidLanUi, "HrElGetInterfaceParams failed with error %ld",
  3650. LresFromHr(hr));
  3651. break;
  3652. }
  3653. // Read the EAPCFG information from the registry and find the node
  3654. // selected in the entry, or the default, if none.
  3655. pListEapcfgs = NULL;
  3656. if (EapolIntfState.dwPhysicalMediumType == NdisPhysicalMediumWirelessLan)
  3657. {
  3658. dwFlags |= EAPOL_MUTUAL_AUTH_EAP_ONLY;
  3659. }
  3660. pListEapcfgs = ::ReadEapcfgList (dwFlags);
  3661. if (pListEapcfgs)
  3662. {
  3663. TraceTag (ttidLanUi, "HrElGetInterfaceParams: Got EAPtype=(%ld), EAPState =(%ld)", EapolIntfParams.dwEapType, EapolIntfParams.dwEapFlags);
  3664. // Enable all windows only for admins
  3665. // if (FIsUserAdmin())
  3666. {
  3667. fFlag = TRUE;
  3668. }
  3669. ::EnableWindow(GetDlgItem(CID_CA_RB_Eap), fFlag);
  3670. if (IS_EAPOL_ENABLED(EapolIntfParams.dwEapFlags))
  3671. {
  3672. Button_SetCheck(GetDlgItem(CID_CA_RB_Eap), TRUE);
  3673. CheckDlgButton(CID_CA_RB_Eap, TRUE);
  3674. ::EnableWindow(GetDlgItem(IDC_TXT_EAP_TYPE), fFlag);
  3675. ::EnableWindow(GetDlgItem(CID_CA_LB_EapPackages), fFlag);
  3676. ::EnableWindow(GetDlgItem(CID_CA_RB_MachineAuth), fFlag);
  3677. if (IS_MACHINE_AUTH_ENABLED(EapolIntfParams.dwEapFlags))
  3678. Button_SetCheck(GetDlgItem(CID_CA_RB_MachineAuth), TRUE);
  3679. ::EnableWindow(GetDlgItem(CID_CA_RB_GuestAuth), fFlag);
  3680. if (IS_GUEST_AUTH_ENABLED(EapolIntfParams.dwEapFlags))
  3681. Button_SetCheck(GetDlgItem(CID_CA_RB_GuestAuth), TRUE);
  3682. }
  3683. else
  3684. {
  3685. ::EnableWindow(GetDlgItem(CID_CA_RB_MachineAuth), FALSE);
  3686. if (IS_MACHINE_AUTH_ENABLED(EapolIntfParams.dwEapFlags))
  3687. Button_SetCheck(GetDlgItem(CID_CA_RB_MachineAuth), TRUE);
  3688. ::EnableWindow(GetDlgItem(CID_CA_RB_GuestAuth), FALSE);
  3689. if (IS_GUEST_AUTH_ENABLED(EapolIntfParams.dwEapFlags))
  3690. Button_SetCheck(GetDlgItem(CID_CA_RB_GuestAuth), TRUE);
  3691. }
  3692. // Read the EAP configuration info for all EAP packages
  3693. for (pNodeEap = DtlGetFirstNode(pListEapcfgs);
  3694. pNodeEap;
  3695. pNodeEap = DtlGetNextNode(pNodeEap))
  3696. {
  3697. EAPCFG* pEapcfg = (EAPCFG* )DtlGetData(pNodeEap);
  3698. ASSERT( pEapcfg );
  3699. hr = S_OK;
  3700. TraceTag (ttidLanUi, "Calling HrElGetCustomAuthData for EAP %ld",
  3701. pEapcfg->dwKey);
  3702. cbData = 0;
  3703. // Get the size of the EAP blob
  3704. hr = HrElGetCustomAuthData (
  3705. wszGuid,
  3706. pEapcfg->dwKey,
  3707. EapolIntfParams.dwSizeOfSSID,
  3708. EapolIntfParams.bSSID,
  3709. NULL,
  3710. &cbData
  3711. );
  3712. if (!SUCCEEDED(hr))
  3713. {
  3714. if ((EapolIntfParams.dwSizeOfSSID != 0) &&
  3715. (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)))
  3716. {
  3717. TraceTag (ttidLanUi, "HrElGetCustomAuthData: SSID!= NULL, not found blob for SSID");
  3718. // The Last Used SSID did not have a connection
  3719. // blob created. Call again for size of blob with
  3720. // NULL SSID
  3721. EapolIntfParams.dwSizeOfSSID = 0;
  3722. // Get the size of the EAP blob
  3723. hr = HrElGetCustomAuthData (
  3724. wszGuid,
  3725. pEapcfg->dwKey,
  3726. 0,
  3727. NULL,
  3728. NULL,
  3729. &cbData
  3730. );
  3731. }
  3732. if (hr == E_OUTOFMEMORY)
  3733. {
  3734. if (cbData <= 0)
  3735. {
  3736. // No EAP blob stored in the registry
  3737. TraceTag (ttidLanUi, "HrElGetCustomAuthData: No blob stored in reg at all");
  3738. pbData = NULL;
  3739. // Will continue processing for errors
  3740. // Not exit
  3741. }
  3742. else
  3743. {
  3744. TraceTag (ttidLanUi, "HrElGetCustomAuthData: Found auth blob in registry");
  3745. // Allocate memory to hold the blob
  3746. pbData = (PBYTE) MALLOC (cbData);
  3747. if (pbData == NULL)
  3748. {
  3749. hr = E_OUTOFMEMORY;
  3750. TraceTag (ttidLanUi, "HrElGetCustomAuthData: Error in memory allocation for EAP blob");
  3751. continue;
  3752. }
  3753. ZeroMemory (pbData, cbData);
  3754. hr = HrElGetCustomAuthData (
  3755. wszGuid,
  3756. pEapcfg->dwKey,
  3757. EapolIntfParams.dwSizeOfSSID,
  3758. EapolIntfParams.bSSID,
  3759. pbData,
  3760. &cbData
  3761. );
  3762. if (!SUCCEEDED(hr))
  3763. {
  3764. TraceTag (ttidLanUi, "HrElGetCustomAuthData: HrElGetCustomAuthData failed with %ld",
  3765. LresFromHr(hr));
  3766. FREE ( pbData );
  3767. hr = S_OK;
  3768. continue;
  3769. }
  3770. TraceTag (ttidLanUi, "HrElGetCustomAuthData: HrElGetCustomAuthData successfully got blob of length %ld"
  3771. , cbData);
  3772. }
  3773. }
  3774. else
  3775. {
  3776. TraceTag (ttidLanUi, "HrElGetCustomAuthData: Not got ERROR_NOT_ENOUGH_MEMORY error; Unknown error !!!");
  3777. continue;
  3778. }
  3779. }
  3780. else
  3781. {
  3782. // HrElGetCustomAuthData will always return
  3783. // error with cbData = 0
  3784. }
  3785. if (pEapcfg->pData != NULL)
  3786. {
  3787. FREE ( pEapcfg->pData );
  3788. }
  3789. pEapcfg->pData = (UCHAR *)pbData;
  3790. pEapcfg->cbData = cbData;
  3791. }
  3792. // Choose the EAP name that will appear in the combo box
  3793. pNode = EapcfgNodeFromKey(
  3794. pListEapcfgs, EapolIntfParams.dwEapType );
  3795. pOriginalEapcfgNode = pNode;
  3796. // Fill the EAP packages listbox and select the previously identified
  3797. // selection. The Properties button is disabled by default, but may
  3798. // be enabled when the EAP list selection is set.
  3799. ::EnableWindow(GetDlgItem(CID_CA_PB_Properties), FALSE);
  3800. for (pNode = DtlGetFirstNode( pListEapcfgs );
  3801. pNode;
  3802. pNode = DtlGetNextNode( pNode ))
  3803. {
  3804. EAPCFG* pEapcfg = NULL;
  3805. INT i;
  3806. TCHAR* pszBuf = NULL;
  3807. pEapcfg = (EAPCFG* )DtlGetData( pNode );
  3808. ASSERT( pEapcfg );
  3809. ASSERT( pEapcfg->pszFriendlyName );
  3810. pszBuf = (TCHAR *) MALLOC (( lstrlen(pEapcfg->pszFriendlyName) + 1 ) * sizeof(TCHAR));
  3811. if (!pszBuf)
  3812. {
  3813. continue;
  3814. }
  3815. lstrcpy( pszBuf, pEapcfg->pszFriendlyName );
  3816. i = ComboBox_AddItem( GetDlgItem(CID_CA_LB_EapPackages),
  3817. pszBuf, pNode );
  3818. if (pNode == pOriginalEapcfgNode)
  3819. {
  3820. // Select the EAP name that will appear in the
  3821. // combo box
  3822. ComboBox_SetCurSelNotify( GetDlgItem(CID_CA_LB_EapPackages), i );
  3823. }
  3824. FREE ( pszBuf );
  3825. }
  3826. }
  3827. ComboBox_AutoSizeDroppedWidth( GetDlgItem(CID_CA_LB_EapPackages) );
  3828. // Disable the Properties button, if EAPOL is not enabled
  3829. // or if the user is not AdminUser
  3830. // if ((!FIsUserAdmin()) || (!IS_EAPOL_ENABLED(EapolIntfParams.dwEapFlags)))
  3831. if ((!IS_EAPOL_ENABLED(EapolIntfParams.dwEapFlags)))
  3832. {
  3833. ::EnableWindow (GetDlgItem(CID_CA_PB_Properties), FALSE);
  3834. }
  3835. } while (FALSE);
  3836. return LresFromHr(hr);
  3837. }
  3838. //+---------------------------------------------------------------------------
  3839. //
  3840. // Member: CLanSecurityPage::OnContextMenu
  3841. //
  3842. // Purpose: When right click a control, bring up help
  3843. //
  3844. // Arguments: Standard command parameters
  3845. //
  3846. // Returns:
  3847. //
  3848. // Author: sachins
  3849. //
  3850. LRESULT
  3851. CLanSecurityPage::OnContextMenu(UINT uMsg,
  3852. WPARAM wParam,
  3853. LPARAM lParam,
  3854. BOOL& fHandled)
  3855. {
  3856. TraceFileFunc(ttidLanUi);
  3857. if (m_adwHelpIDs != NULL)
  3858. {
  3859. ::WinHelp(m_hWnd,
  3860. c_szNetCfgHelpFile,
  3861. HELP_CONTEXTMENU,
  3862. (ULONG_PTR)m_adwHelpIDs);
  3863. }
  3864. return 0;
  3865. }
  3866. //+---------------------------------------------------------------------------
  3867. //
  3868. // Member: CLanSecurityPage::OnHelp
  3869. //
  3870. // Purpose: When drag context help icon over a control, bring up help
  3871. //
  3872. // Arguments: Standard command parameters
  3873. //
  3874. // Returns:
  3875. //
  3876. // Author: sachins
  3877. //
  3878. LRESULT
  3879. CLanSecurityPage::OnHelp( UINT uMsg,
  3880. WPARAM wParam,
  3881. LPARAM lParam,
  3882. BOOL& fHandled)
  3883. {
  3884. TraceFileFunc(ttidLanUi);
  3885. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  3886. Assert(lphi);
  3887. if ((m_adwHelpIDs != NULL) && (HELPINFO_WINDOW == lphi->iContextType))
  3888. {
  3889. ::WinHelp(static_cast<HWND>(lphi->hItemHandle),
  3890. c_szNetCfgHelpFile,
  3891. HELP_WM_HELP,
  3892. (ULONG_PTR)m_adwHelpIDs);
  3893. }
  3894. return 0;
  3895. }
  3896. //+---------------------------------------------------------------------------
  3897. //
  3898. // Member: CLanSecurityPage::OnDestroy
  3899. //
  3900. // Purpose: Called when the dialog page is destroyed
  3901. //
  3902. // Arguments:
  3903. // uMsg []
  3904. // wParam []
  3905. // lParam []
  3906. // bHandled []
  3907. //
  3908. // Returns:
  3909. //
  3910. // Author: sachins
  3911. //
  3912. // Notes:
  3913. //
  3914. LRESULT CLanSecurityPage::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam,
  3915. BOOL& bHandled)
  3916. {
  3917. TraceFileFunc(ttidLanUi);
  3918. if (pListEapcfgs)
  3919. {
  3920. DtlDestroyList (pListEapcfgs, DestroyEapcfgNode);
  3921. }
  3922. pListEapcfgs = NULL;
  3923. return 0;
  3924. }
  3925. //+---------------------------------------------------------------------------
  3926. //
  3927. // Member: CLanSecurityPage::OnProperties
  3928. //
  3929. // Purpose: Handles the clicking of the Properties button
  3930. //
  3931. // Arguments:
  3932. // wNotifyCode []
  3933. // wID []
  3934. // hWndCtl []
  3935. // bHandled []
  3936. //
  3937. // Returns: error code
  3938. //
  3939. // Author: sachins
  3940. //
  3941. // Notes:
  3942. //
  3943. LRESULT CLanSecurityPage::OnProperties(WORD wNotifyCode, WORD wID,
  3944. HWND hWndCtl, BOOL& bHandled)
  3945. {
  3946. TraceFileFunc(ttidLanUi);
  3947. DWORD dwErr = 0;
  3948. DTLNODE* pNode = NULL;
  3949. EAPCFG* pEapcfg = NULL;
  3950. RASEAPINVOKECONFIGUI pInvokeConfigUi;
  3951. RASEAPFREE pFreeConfigUIData;
  3952. HINSTANCE h;
  3953. BYTE* pConnectionData = NULL;
  3954. DWORD cbConnectionData = 0;
  3955. HRESULT hr = S_OK;
  3956. // Look up the selected package configuration and load the associated
  3957. // configuration DLL.
  3958. pNode = (DTLNODE* )ComboBox_GetItemDataPtr(
  3959. GetDlgItem(CID_CA_LB_EapPackages),
  3960. ComboBox_GetCurSel( GetDlgItem(CID_CA_LB_EapPackages) ) );
  3961. ASSERT( pNode );
  3962. if (!pNode)
  3963. {
  3964. return E_UNEXPECTED;
  3965. }
  3966. pEapcfg = (EAPCFG* )DtlGetData( pNode );
  3967. ASSERT( pEapcfg );
  3968. h = NULL;
  3969. if (!(h = LoadLibrary( pEapcfg->pszConfigDll ))
  3970. || !(pInvokeConfigUi =
  3971. (RASEAPINVOKECONFIGUI )GetProcAddress(
  3972. h, "RasEapInvokeConfigUI" ))
  3973. || !(pFreeConfigUIData =
  3974. (RASEAPFREE) GetProcAddress(
  3975. h, "RasEapFreeMemory" )))
  3976. {
  3977. // Cannot load configuration DLL
  3978. if (h)
  3979. {
  3980. FreeLibrary( h );
  3981. }
  3982. return E_FAIL;
  3983. }
  3984. // Call the configuration DLL to popup it's custom configuration UI.
  3985. pConnectionData = NULL;
  3986. cbConnectionData = 0;
  3987. dwErr = pInvokeConfigUi(
  3988. pEapcfg->dwKey,
  3989. GetParent(),
  3990. RAS_EAP_FLAG_8021X_AUTH,
  3991. pEapcfg->pData,
  3992. pEapcfg->cbData,
  3993. &pConnectionData,
  3994. &cbConnectionData
  3995. );
  3996. if (dwErr != 0)
  3997. {
  3998. FreeLibrary( h );
  3999. return E_FAIL;
  4000. }
  4001. // Store the configuration information returned in the package descriptor.
  4002. FREE ( pEapcfg->pData );
  4003. pEapcfg->pData = NULL;
  4004. pEapcfg->cbData = 0;
  4005. if (pConnectionData)
  4006. {
  4007. if (cbConnectionData > 0)
  4008. {
  4009. // Copy it into the eap node
  4010. pEapcfg->pData = (PUCHAR) MALLOC (cbConnectionData);
  4011. if (pEapcfg->pData)
  4012. {
  4013. CopyMemory( pEapcfg->pData, pConnectionData, cbConnectionData );
  4014. pEapcfg->cbData = cbConnectionData;
  4015. }
  4016. }
  4017. }
  4018. pFreeConfigUIData( pConnectionData );
  4019. // Note any "force user to configure" requirement on the package has been
  4020. // satisfied.
  4021. pEapcfg->fConfigDllCalled = TRUE;
  4022. FreeLibrary( h );
  4023. TraceError("CLanSecurityPage::OnProperties", hr);
  4024. return LresFromHr(hr);
  4025. }
  4026. //+---------------------------------------------------------------------------
  4027. //
  4028. // Member: CLanSecurityPage::OnEapSelection
  4029. //
  4030. // Purpose: Handles the clicking of the EAP checkbox
  4031. //
  4032. // Arguments:
  4033. // wNotifyCode []
  4034. // wID []
  4035. // hWndCtl []
  4036. // bHandled []
  4037. //
  4038. // Returns:
  4039. //
  4040. // Author: sachins
  4041. //
  4042. // Notes:
  4043. //
  4044. LRESULT CLanSecurityPage::OnEapSelection(WORD wNotifyCode, WORD wID,
  4045. HWND hWndCtl, BOOL& bHandled)
  4046. {
  4047. TraceFileFunc(ttidLanUi);
  4048. HRESULT hr = S_OK;
  4049. EAPCFG* pEapcfg = NULL;
  4050. INT iSel = 0;
  4051. // Toggle buttons based on selection
  4052. if (BST_CHECKED == IsDlgButtonChecked(CID_CA_RB_Eap))
  4053. {
  4054. ::EnableWindow(GetDlgItem(CID_CA_LB_EapPackages), TRUE);
  4055. ::EnableWindow(GetDlgItem(IDC_TXT_EAP_TYPE), TRUE);
  4056. // Get the EAPCFG information for the currently selected EAP package.
  4057. iSel = ComboBox_GetCurSel(GetDlgItem(CID_CA_LB_EapPackages));
  4058. // iSel is the index in the displayed list as well as the
  4059. // index of the dll that are loaded.
  4060. // Get the cfgnode corresponding to this index
  4061. if (iSel >= 0)
  4062. {
  4063. DTLNODE* pNode;
  4064. pNode =
  4065. (DTLNODE* )ComboBox_GetItemDataPtr(
  4066. GetDlgItem(CID_CA_LB_EapPackages), iSel );
  4067. if (pNode)
  4068. {
  4069. pEapcfg = (EAPCFG* )DtlGetData( pNode );
  4070. }
  4071. }
  4072. // Enable the Properties button if the selected package has a
  4073. // configuration entrypoint
  4074. // if (FIsUserAdmin())
  4075. {
  4076. ::EnableWindow ( GetDlgItem(CID_CA_PB_Properties),
  4077. (pEapcfg && !!(pEapcfg->pszConfigDll)) );
  4078. }
  4079. ::EnableWindow(GetDlgItem(CID_CA_RB_MachineAuth), TRUE);
  4080. ::EnableWindow(GetDlgItem(CID_CA_RB_GuestAuth), TRUE);
  4081. }
  4082. else
  4083. {
  4084. ::EnableWindow(GetDlgItem (IDC_TXT_EAP_TYPE), FALSE);
  4085. ::EnableWindow(GetDlgItem (CID_CA_LB_EapPackages), FALSE);
  4086. ::EnableWindow(GetDlgItem (CID_CA_PB_Properties), FALSE);
  4087. ::EnableWindow(GetDlgItem(CID_CA_RB_MachineAuth), FALSE);
  4088. ::EnableWindow(GetDlgItem(CID_CA_RB_GuestAuth), FALSE);
  4089. }
  4090. TraceError("CLanSecurityPage::OnEapSelection", hr);
  4091. return LresFromHr(hr);
  4092. }
  4093. //+---------------------------------------------------------------------------
  4094. //
  4095. // Member: CLanSecurityPage::OnEapPackages
  4096. //
  4097. // Purpose: Handles the clicking of the EAP packages combo box
  4098. //
  4099. // Arguments:
  4100. // wNotifyCode []
  4101. // wID []
  4102. // hWndCtl []
  4103. // bHandled []
  4104. //
  4105. // Returns:
  4106. //
  4107. // Author: sachins
  4108. //
  4109. // Notes:
  4110. //
  4111. LRESULT CLanSecurityPage::OnEapPackages(WORD wNotifyCode, WORD wID,
  4112. HWND hWndCtl, BOOL& bHandled)
  4113. {
  4114. TraceFileFunc(ttidLanUi);
  4115. HRESULT hr = S_OK;
  4116. EAPCFG* pEapcfg = NULL;
  4117. INT iSel = 0;
  4118. // Get the EAPCFG information for the selected EAP package.
  4119. iSel = ComboBox_GetCurSel(GetDlgItem(CID_CA_LB_EapPackages));
  4120. // iSel is the index in the displayed list as well as the
  4121. // index of the dll that are loaded.
  4122. // Get the cfgnode corresponding to this index
  4123. if (iSel >= 0)
  4124. {
  4125. DTLNODE* pNode = NULL;
  4126. pNode =
  4127. (DTLNODE* )ComboBox_GetItemDataPtr(
  4128. GetDlgItem(CID_CA_LB_EapPackages), iSel );
  4129. if (pNode)
  4130. {
  4131. pEapcfg = (EAPCFG* )DtlGetData( pNode );
  4132. }
  4133. }
  4134. // Enable the Properties button if the selected package has a
  4135. // configuration entrypoint
  4136. if (BST_CHECKED == IsDlgButtonChecked(CID_CA_RB_Eap))
  4137. {
  4138. ::EnableWindow ( GetDlgItem(CID_CA_PB_Properties),
  4139. (pEapcfg && !!(pEapcfg?pEapcfg->pszConfigDll:NULL)) );
  4140. }
  4141. TraceError("CLanSecurityPage::OnEapPackages", hr);
  4142. return LresFromHr(hr);
  4143. }
  4144. //+---------------------------------------------------------------------------
  4145. //
  4146. // Member: CLanSecurityPage::OnKillActive
  4147. //
  4148. // Purpose: Called to check warning conditions before the security
  4149. // page is going away
  4150. //
  4151. // Arguments:
  4152. // idCtrl []
  4153. // pnmh []
  4154. // bHandled []
  4155. //
  4156. // Returns:
  4157. //
  4158. // Author: sachins
  4159. //
  4160. // Notes:
  4161. //
  4162. LRESULT CLanSecurityPage::OnKillActive(int idCtrl, LPNMHDR pnmh,
  4163. BOOL& bHandled)
  4164. {
  4165. TraceFileFunc(ttidLanUi);
  4166. BOOL fError;
  4167. fError = m_fNetcfgInUse;
  4168. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, fError);
  4169. return fError;
  4170. }
  4171. //+---------------------------------------------------------------------------
  4172. //
  4173. // Member: CLanSecurityPage::OnApply
  4174. //
  4175. // Purpose: Called when the Networking page is applied
  4176. //
  4177. // Arguments:
  4178. // idCtrl []
  4179. // pnmh []
  4180. // bHandled []
  4181. //
  4182. // Returns:
  4183. //
  4184. // Author: sachins
  4185. //
  4186. // Notes:
  4187. //
  4188. LRESULT CLanSecurityPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  4189. {
  4190. TraceFileFunc(ttidLanUi);
  4191. WCHAR wszGuid[c_cchGuidWithTerm];
  4192. WCHAR *pwszLastUsedSSID = NULL;
  4193. DWORD dwSizeofSSID = 0;
  4194. DWORD dwEapFlags = 0;
  4195. DWORD dwDefaultEapType = 0;
  4196. EAPOL_INTF_PARAMS EapolIntfParams;
  4197. NETCON_PROPERTIES* pProps = NULL;
  4198. HRESULT hrOverall = S_OK;
  4199. HRESULT hr = S_OK;
  4200. // Save the EAP configuration data into the registry
  4201. DTLNODE* pNodeEap = NULL;
  4202. #if 0
  4203. if (!FIsUserAdmin())
  4204. {
  4205. TraceTag (ttidLanUi, "CLanSecurityPage::OnApply: Non-admin user, not saving data");
  4206. return LresFromHr(hr);
  4207. }
  4208. #endif
  4209. hr = m_pconn->GetProperties(&pProps);
  4210. if (!SUCCEEDED(hr))
  4211. {
  4212. TraceTag (ttidLanUi, "CLanSecurityPage::OnApply: Error in m_pconn->GetProperties");
  4213. return LresFromHr(hr);
  4214. }
  4215. hr = S_OK;
  4216. if (::StringFromGUID2(pProps->guidId, wszGuid, c_cchGuidWithTerm) == 0)
  4217. {
  4218. TraceTag (ttidLanUi, "CLanSecurityPage::OnApply: StringFromGUID2 failed");
  4219. FreeNetconProperties(pProps);
  4220. hr = E_FAIL;
  4221. return LresFromHr(hr);
  4222. }
  4223. FreeNetconProperties(pProps);
  4224. // Get the Last Used SSID on the interface and set the
  4225. // EAP blob for that interface
  4226. ZeroMemory ((BYTE *)&EapolIntfParams, sizeof(EAPOL_INTF_PARAMS));
  4227. EapolIntfParams.dwEapFlags = DEFAULT_EAP_STATE;
  4228. hr = HrElGetInterfaceParams (
  4229. wszGuid,
  4230. &EapolIntfParams
  4231. );
  4232. if (FAILED(hr))
  4233. {
  4234. TraceTag (ttidLanUi, "OnApply: HrElGetInterfaceParams failed with error %ld",
  4235. LresFromHr(hr));
  4236. return LresFromHr(hr);
  4237. }
  4238. // Save data for all EAP packages in the registry
  4239. if (pListEapcfgs == NULL)
  4240. {
  4241. return LresFromHr(S_OK);
  4242. }
  4243. {
  4244. DTLNODE* pNode = NULL;
  4245. EAPCFG* pEapcfg = NULL;
  4246. pNode = (DTLNODE* )ComboBox_GetItemDataPtr(
  4247. GetDlgItem (CID_CA_LB_EapPackages),
  4248. ComboBox_GetCurSel( GetDlgItem (CID_CA_LB_EapPackages) ) );
  4249. if (pNode == NULL)
  4250. {
  4251. return LresFromHr (E_FAIL);
  4252. }
  4253. pEapcfg = (EAPCFG* )DtlGetData( pNode );
  4254. if (pEapcfg == NULL)
  4255. {
  4256. return LresFromHr (E_FAIL);
  4257. }
  4258. dwDefaultEapType = pEapcfg->dwKey;
  4259. }
  4260. for (pNodeEap = DtlGetFirstNode(pListEapcfgs);
  4261. pNodeEap;
  4262. pNodeEap = DtlGetNextNode(pNodeEap))
  4263. {
  4264. EAPCFG* pcfg = (EAPCFG* )DtlGetData(pNodeEap);
  4265. if (pcfg == NULL)
  4266. {
  4267. continue;
  4268. }
  4269. hr = S_OK;
  4270. TraceTag (ttidLanUi, "Saving data for EAP Id = %ld", pcfg->dwKey);
  4271. TraceTag (ttidLanUi, "OnApply: Setting customauthdata for %S",
  4272. wszGuid);
  4273. // ignore error and continue with next
  4274. hr = HrElSetCustomAuthData (
  4275. wszGuid,
  4276. pcfg->dwKey,
  4277. EapolIntfParams.dwSizeOfSSID,
  4278. EapolIntfParams.bSSID,
  4279. pcfg->pData,
  4280. pcfg->cbData);
  4281. if (FAILED (hr))
  4282. {
  4283. TraceTag (ttidLanUi, "HrElSetCustomAuthData failed");
  4284. hrOverall = hr;
  4285. hr = S_OK;
  4286. }
  4287. else
  4288. {
  4289. TraceTag (ttidLanUi, "HrElSetCustomAuthData succeeded");
  4290. }
  4291. FREE (pcfg->pData);
  4292. pcfg->pData = NULL;
  4293. pcfg->cbData = 0;
  4294. }
  4295. // If CID_CA_RB_Eap is checked, EAPOL is enabled on the interface
  4296. if ( Button_GetCheck( GetDlgItem(CID_CA_RB_Eap) ) )
  4297. {
  4298. dwEapFlags |= EAPOL_ENABLED;
  4299. if (Button_GetCheck( GetDlgItem(CID_CA_RB_MachineAuth )))
  4300. dwEapFlags |= EAPOL_MACHINE_AUTH_ENABLED;
  4301. if (Button_GetCheck( GetDlgItem(CID_CA_RB_GuestAuth )))
  4302. dwEapFlags |= EAPOL_GUEST_AUTH_ENABLED;
  4303. // Save the params for this interface in registry
  4304. EapolIntfParams.dwEapType = dwDefaultEapType;
  4305. EapolIntfParams.dwEapFlags = dwEapFlags;
  4306. hr = HrElSetInterfaceParams (
  4307. wszGuid,
  4308. &EapolIntfParams
  4309. );
  4310. if (FAILED(hr))
  4311. {
  4312. TraceTag (ttidLanUi, "HrElSetInterfaceParams enabled failed with error %ld",
  4313. LresFromHr(hr));
  4314. hrOverall = hr;
  4315. hr = S_OK;
  4316. }
  4317. }
  4318. else
  4319. {
  4320. dwEapFlags |= EAPOL_DISABLED;
  4321. if (Button_GetCheck( GetDlgItem(CID_CA_RB_MachineAuth )))
  4322. dwEapFlags |= EAPOL_MACHINE_AUTH_ENABLED;
  4323. if (Button_GetCheck( GetDlgItem(CID_CA_RB_GuestAuth )))
  4324. dwEapFlags |= EAPOL_GUEST_AUTH_ENABLED;
  4325. // Save the params for this interface in registry
  4326. EapolIntfParams.dwEapType = dwDefaultEapType;
  4327. EapolIntfParams.dwEapFlags = dwEapFlags;
  4328. hr = HrElSetInterfaceParams (
  4329. wszGuid,
  4330. &EapolIntfParams
  4331. );
  4332. if (FAILED(hr))
  4333. {
  4334. TraceTag (ttidLanUi, "HrElSetInterfaceParams EAPOL disabled failed with error %ld",
  4335. LresFromHr(hr));
  4336. hrOverall = hr;
  4337. hr = S_OK;
  4338. }
  4339. }
  4340. if (FAILED(hrOverall))
  4341. {
  4342. NcMsgBox(
  4343. _Module.GetResourceInstance(),
  4344. m_hWnd,
  4345. IDS_LANUI_ERROR_CAPTION,
  4346. IDS_EAPOL_PARTIAL_APPLY,
  4347. MB_ICONSTOP|MB_OK);
  4348. }
  4349. return LresFromHr(hr);
  4350. }
  4351. //+---------------------------------------------------------------------------
  4352. //
  4353. // Member: CLanSecurityPage::OnCancel
  4354. //
  4355. // Purpose: Called when the Networking page is cancelled.
  4356. //
  4357. // Arguments:
  4358. // idCtrl []
  4359. // pnmh []
  4360. // bHandled []
  4361. //
  4362. // Returns:
  4363. //
  4364. // Author: sachins
  4365. //
  4366. //
  4367. LRESULT CLanSecurityPage::OnCancel(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  4368. {
  4369. TraceFileFunc(ttidLanUi);
  4370. if (pListEapcfgs)
  4371. {
  4372. DtlDestroyList (pListEapcfgs, DestroyEapcfgNode);
  4373. }
  4374. pListEapcfgs = NULL;
  4375. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, m_fNetcfgInUse);
  4376. return m_fNetcfgInUse;
  4377. }