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.

669 lines
21 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "ncui.h"
  4. #include "ncmisc.h"
  5. #include "netcfgn.h"
  6. #include "netshell.h"
  7. #include "resource.h"
  8. #include "nsres.h" // For Icon's
  9. #include "wizard.h"
  10. #include "..\folder\foldres.h"
  11. #include "wgenericpage.h"
  12. // Setup Wizard Global - Only used during setup.
  13. CWizard * g_pSetupWizard = NULL;
  14. //
  15. // Function: HrRequestWizardPages
  16. //
  17. // Purpose: To supply a max count of wizard pages or to supply and actual
  18. // count and the actual pages
  19. //
  20. // Parameters:
  21. //
  22. // Returns: HRESULT, S_OK if the function succeeded
  23. // S_FALSE if no pages were returned
  24. // otherwise a failure HRESULT
  25. //
  26. HRESULT HrRequestWizardPages(CWizard **ppWizard,
  27. BOOL fLanPages,
  28. ProviderList * rgpProviders,
  29. ULONG cProviders,
  30. HPROPSHEETPAGE* pahpsp,
  31. UINT* pcPages,
  32. PINTERNAL_SETUP_DATA pData,
  33. BOOL fDeferProviderLoad)
  34. {
  35. HRESULT hr = S_OK;
  36. Assert(NULL != pData);
  37. if ((NULL == pData) ||
  38. (sizeof(INTERNAL_SETUP_DATA) < pData->dwSizeOf))
  39. {
  40. hr = E_INVALIDARG;
  41. }
  42. else if (pcPages && pData)
  43. {
  44. UINT cProviderPages = 0;
  45. BOOL fCountOnly = (NULL == pahpsp);
  46. CWizard * pWizard = *ppWizard;
  47. // Create the Wizard object if not already created
  48. if (NULL == pWizard)
  49. {
  50. // Create the wizard interface
  51. HRESULT hr = CWizard::HrCreate(&pWizard, fLanPages, pData, fDeferProviderLoad);
  52. if (FAILED(hr))
  53. {
  54. TraceHr(ttidWizard, FAL, hr, FALSE, "HrRequestWizardPages");
  55. return hr;
  56. }
  57. Assert(NULL != pWizard);
  58. *ppWizard = pWizard;
  59. // If there is an unattended file, read the options (READONLY, etc)
  60. //
  61. ReadAnswerFileSetupOptions(pWizard);
  62. }
  63. // Count/Create all necessary pages
  64. *pcPages = 0;
  65. Assert(NULL != pWizard);
  66. Assert(NULL != pData);
  67. Assert(NULL != pcPages);
  68. // Load the wizard page providers used in setup
  69. pWizard->LoadWizProviders(cProviders, rgpProviders);
  70. if (!pWizard->FDeferredProviderLoad())
  71. {
  72. // Count/Create Provider Pages first
  73. hr = pWizard->HrCreateWizProviderPages(fCountOnly, &cProviderPages);
  74. if (FAILED(hr))
  75. {
  76. goto Error;
  77. }
  78. (*pcPages) += cProviderPages;
  79. }
  80. // Count/Create all other pages
  81. hr = HrCreateUpgradePage(pWizard, pData, fCountOnly, pcPages);
  82. if (FAILED(hr))
  83. {
  84. goto Error;
  85. }
  86. hr = HrCreateMainIntroPage(pWizard, pData, fCountOnly, pcPages);
  87. if (FAILED(hr))
  88. {
  89. goto Error;
  90. }
  91. hr = HrCreateMainPage(pWizard, pData, fCountOnly, pcPages);
  92. if (FAILED(hr))
  93. {
  94. goto Error;
  95. }
  96. hr = HrCreateISPPage(pWizard, pData, fCountOnly, pcPages);
  97. if (FAILED(hr))
  98. {
  99. goto Error;
  100. }
  101. hr = HrCreateInternetPage(pWizard, pData, fCountOnly, pcPages);
  102. if (FAILED(hr))
  103. {
  104. goto Error;
  105. }
  106. hr = CGenericFinishPage::HrCreateCGenericFinishPagePage(IDD_FinishOtherWays, pWizard, pData, fCountOnly, pcPages);
  107. if (FAILED(hr))
  108. {
  109. goto Error;
  110. }
  111. hr = CGenericFinishPage::HrCreateCGenericFinishPagePage(IDD_ISPSoftwareCD, pWizard, pData, fCountOnly, pcPages);
  112. if (FAILED(hr))
  113. {
  114. goto Error;
  115. }
  116. hr = CGenericFinishPage::HrCreateCGenericFinishPagePage(IDD_Broadband_Always_On, pWizard, pData, fCountOnly, pcPages);
  117. if (FAILED(hr))
  118. {
  119. goto Error;
  120. }
  121. hr = CGenericFinishPage::HrCreateCGenericFinishPagePage(IDD_FinishNetworkSetupWizard, pWizard, pData, fCountOnly, pcPages);
  122. if (FAILED(hr))
  123. {
  124. goto Error;
  125. }
  126. hr = HrCreateConnectPage(pWizard, pData, fCountOnly, pcPages);
  127. if (FAILED(hr))
  128. {
  129. goto Error;
  130. }
  131. hr = HrCreateAdvancedPage(pWizard, pData, fCountOnly, pcPages);
  132. if (FAILED(hr))
  133. {
  134. goto Error;
  135. }
  136. hr = HrCreateFinishPage(pWizard, pData, fCountOnly, pcPages);
  137. if (FAILED(hr))
  138. {
  139. goto Error;
  140. }
  141. hr = HrCreateJoinPage(pWizard, pData, fCountOnly, pcPages);
  142. if (FAILED(hr))
  143. {
  144. goto Error;
  145. }
  146. if (*pcPages)
  147. {
  148. hr = HrCreateExitPage(pWizard, pData, fCountOnly, pcPages);
  149. if (FAILED(hr))
  150. {
  151. goto Error;
  152. }
  153. }
  154. hr = HrCreateNetDevPage(pWizard, pData, fCountOnly, pcPages);
  155. if (FAILED(hr))
  156. {
  157. goto Error;
  158. }
  159. // Assemble all created pages into the output array
  160. if (!fCountOnly)
  161. {
  162. UINT cExpected = *pcPages;
  163. *pcPages = 0;
  164. Assert(NULL != pahpsp);
  165. AppendUpgradePage(pWizard, pahpsp, pcPages);
  166. AppendMainIntroPage(pWizard, pahpsp, pcPages);
  167. AppendMainPage(pWizard, pahpsp, pcPages);
  168. AppendISPPage(pWizard, pahpsp, pcPages);
  169. AppendInternetPage(pWizard, pahpsp, pcPages);
  170. CGenericFinishPage::AppendCGenericFinishPagePage(IDD_FinishOtherWays, pWizard, pahpsp, pcPages);
  171. CGenericFinishPage::AppendCGenericFinishPagePage(IDD_ISPSoftwareCD, pWizard, pahpsp, pcPages);
  172. CGenericFinishPage::AppendCGenericFinishPagePage(IDD_Broadband_Always_On, pWizard, pahpsp, pcPages);
  173. CGenericFinishPage::AppendCGenericFinishPagePage(IDD_FinishNetworkSetupWizard, pWizard, pahpsp, pcPages);
  174. AppendConnectPage(pWizard, pahpsp, pcPages);
  175. AppendAdvancedPage(pWizard, pahpsp, pcPages);
  176. pWizard->AppendProviderPages(pahpsp, pcPages);
  177. AppendFinishPage(pWizard, pahpsp, pcPages);
  178. AppendJoinPage(pWizard, pahpsp, pcPages);
  179. if (*pcPages)
  180. {
  181. AppendExitPage(pWizard, pahpsp, pcPages);
  182. }
  183. AppendNetDevPage(pWizard, pahpsp, pcPages);
  184. Assert(cExpected == *pcPages);
  185. }
  186. if (0 == *pcPages)
  187. {
  188. Assert(SUCCEEDED(hr));
  189. hr = S_FALSE;
  190. }
  191. }
  192. Error:
  193. TraceHr(ttidWizard, FAL, hr,(S_FALSE == hr), "CWizProvider::HrCreate");
  194. return hr;
  195. }
  196. //
  197. // Function: FSetupRequestWizardPages
  198. //
  199. // Purpose: To supply a max count of wizard pages or to supply and actual
  200. // count and the actual pages
  201. //
  202. // Parameters:
  203. //
  204. // Returns: BOOL, TRUE if the function succeeded, false on failure
  205. //
  206. BOOL FSetupRequestWizardPages(HPROPSHEETPAGE* pahpsp,
  207. UINT* pcPages,
  208. PINTERNAL_SETUP_DATA psp)
  209. {
  210. HRESULT hr;
  211. BOOL fCoUninitialze = TRUE;
  212. ProviderList rgProviderLan[] = {{&CLSID_LanConnectionUi, 0}};
  213. Assert(NULL == g_pSetupWizard);
  214. #ifdef DBG
  215. if (FIsDebugFlagSet (dfidBreakOnWizard))
  216. {
  217. ShellExecute(NULL, L"open", L"cmd.exe", NULL, NULL, SW_SHOW);
  218. AssertSz(FALSE, "THIS IS NOT A BUG! The debug flag "
  219. "\"BreakOnWizard\" has been set. Set your breakpoints now.");
  220. }
  221. #endif // DBG
  222. // CoInitialize because setup doesn't do it for us
  223. hr = CoInitializeEx(NULL, COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED);
  224. if (RPC_E_CHANGED_MODE == hr)
  225. {
  226. // Ignore any change mode error
  227. hr = S_OK;
  228. fCoUninitialze = FALSE;
  229. }
  230. if (SUCCEEDED(hr))
  231. {
  232. hr = HrRequestWizardPages(&g_pSetupWizard, TRUE, rgProviderLan,
  233. celems(rgProviderLan), pahpsp, pcPages,
  234. psp, FALSE);
  235. if (S_OK == hr)
  236. {
  237. Assert(NULL != g_pSetupWizard);
  238. g_pSetupWizard->SetCoUninit(fCoUninitialze);
  239. return TRUE;
  240. }
  241. }
  242. return FALSE;
  243. }
  244. //+---------------------------------------------------------------------------
  245. //
  246. // Function: HrSetWizardTaskbarIcon
  247. //
  248. // Purpose: Setup the wizard's taskbar icon.
  249. //
  250. // Arguments:
  251. // hwndDlg [in] Dialog handle
  252. // uMsg [in] Message value
  253. // lparam [in] Long parameter
  254. //
  255. // Returns: 0
  256. //
  257. // Notes: A standard Win32 commctrl PropSheetProc always return 0.
  258. // See MSDN documentation.
  259. //
  260. int CALLBACK HrSetWizardTaskbarIcon(
  261. IN HWND hwndDlg,
  262. IN UINT uMsg,
  263. IN LPARAM lparam)
  264. {
  265. HICON hIcon;
  266. switch (uMsg)
  267. {
  268. case PSCB_INITIALIZED:
  269. // Set the dialog window's icon
  270. hIcon = LoadIcon(_Module.GetResourceInstance(),
  271. MAKEINTRESOURCE(IDI_CONFOLD_WIZARD));
  272. Assert(hIcon);
  273. if (hIcon)
  274. {
  275. SendMessage(hwndDlg,
  276. WM_SETICON,
  277. ICON_BIG,
  278. (LPARAM)(HICON)hIcon);
  279. }
  280. break;
  281. default:
  282. break;
  283. }
  284. return 0;
  285. }
  286. //
  287. // Function: FSetupFreeWizardPages
  288. //
  289. // Purpose: To clean up after the wizard has been used by setup
  290. //
  291. // Parameters:
  292. //
  293. // Returns: BOOL, TRUE if the function succeeded, false on failure
  294. //
  295. BOOL FSetupFreeWizardPages()
  296. {
  297. delete g_pSetupWizard;
  298. g_pSetupWizard = NULL;
  299. return TRUE;
  300. }
  301. EXTERN_C
  302. HRESULT
  303. WINAPI
  304. HrRunWizard(HWND hwnd, BOOL fPnpAddAdapter, INetConnection ** ppConn, DWORD dwFirstPage)
  305. {
  306. DWORD adwTestedPages[] = {0, CHK_MAIN_VPN, IDD_Connect};
  307. CWizard * pWizard = NULL;
  308. PROPSHEETHEADER psh;
  309. HRESULT hr = S_OK;
  310. HPROPSHEETPAGE * phPages = NULL;
  311. INT nRet = 0;
  312. UINT cPages = 0;
  313. PRODUCT_FLAVOR pf;
  314. ProviderList * rgpProviders;
  315. ULONG culProviders;
  316. INTERNAL_SETUP_DATA sp = {0};
  317. BOOL fIsRequestedPageTested = FALSE;
  318. for (DWORD dwCount = 0; dwCount < celems(adwTestedPages); dwCount++)
  319. {
  320. if (adwTestedPages[dwCount] == dwFirstPage)
  321. {
  322. fIsRequestedPageTested = TRUE;
  323. }
  324. }
  325. if (!fIsRequestedPageTested)
  326. {
  327. #ifdef DBG
  328. AssertSz(NULL, "The requested start page passed to HrRunWizard/StartNCW has not been certified to work through the API. "
  329. "If this page indeed works correctly according to your specifications, please update the Requested pages list "
  330. "inside this file. In FRE builds this API will open page 0 instead of asserting.")
  331. #else
  332. dwFirstPage = 0;
  333. #endif
  334. }
  335. if (NULL != ppConn)
  336. {
  337. *ppConn = NULL;
  338. }
  339. // ISSUE - the order of these is critical.
  340. // Backup becomes a problem if the last item is not a provider from the
  341. // advanced dialog. The problem is that whatever provider is the last
  342. // in the list it automatically backs up to the advanced page.
  343. // This should be investigated further after Whistler.
  344. //
  345. // Bug 233403: Add an entry for internet connection through dialup. ICW is no longer called.
  346. ProviderList rgProviderRas[] = {{&CLSID_PPPoEUi, CHK_MAIN_PPPOE},
  347. {&CLSID_VpnConnectionUi, CHK_MAIN_VPN},
  348. {&CLSID_InternetConnectionUi, CHK_MAIN_INTERNET},
  349. {&CLSID_DialupConnectionUi, CHK_MAIN_DIALUP},
  350. {&CLSID_InboundConnectionUi, CHK_MAIN_INBOUND},
  351. {&CLSID_DirectConnectionUi, CHK_MAIN_DIRECT}};
  352. // Begin the wait cursor
  353. {
  354. BOOL fJumpToProviderPage = FALSE;
  355. CWaitCursor wc;
  356. if ((dwFirstPage >= CHK_MAIN_DIALUP) &&
  357. (dwFirstPage <= CHK_MAIN_ADVANCED))
  358. {
  359. fJumpToProviderPage = TRUE;
  360. }
  361. INITCOMMONCONTROLSEX iccex = {0};
  362. iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  363. iccex.dwICC = ICC_LISTVIEW_CLASSES |
  364. ICC_ANIMATE_CLASS |
  365. ICC_USEREX_CLASSES;
  366. SideAssert(InitCommonControlsEx(&iccex));
  367. sp.OperationFlags = SETUPOPER_POSTSYSINSTALL;
  368. sp.dwSizeOf = sizeof(INTERNAL_SETUP_DATA);
  369. sp.SetupMode = SETUPMODE_TYPICAL;
  370. sp.WizardTitle = SzLoadIds(IDS_WIZARD_CAPTION);
  371. sp.SourcePath = NULL;
  372. sp.UnattendFile = NULL;
  373. sp.LegacySourcePath = NULL;
  374. GetProductFlavor (NULL, &pf);
  375. sp.ProductType = (PF_WORKSTATION == pf) ? PRODUCT_WORKSTATION
  376. : PRODUCT_SERVER_STANDALONE;
  377. Assert(!fPnpAddAdapter);
  378. culProviders = celems(rgProviderRas);
  379. rgpProviders = rgProviderRas;
  380. hr = HrRequestWizardPages(&pWizard, fPnpAddAdapter, rgpProviders,
  381. culProviders, NULL, &cPages, &sp, !fJumpToProviderPage);
  382. if ((S_OK != hr) || (0 == cPages) || (NULL == pWizard))
  383. {
  384. goto Done;
  385. }
  386. Assert(pWizard);
  387. if (dwFirstPage)
  388. {
  389. pWizard->SetFirstPage(dwFirstPage);
  390. }
  391. // Allocate the requested pages
  392. phPages = reinterpret_cast<HPROPSHEETPAGE *>
  393. (MemAlloc(sizeof(HPROPSHEETPAGE) * cPages));
  394. if (NULL == phPages)
  395. {
  396. hr = E_OUTOFMEMORY;
  397. TraceHr(ttidWizard, FAL, E_OUTOFMEMORY, FALSE, "HrRunWizard");
  398. goto Done;
  399. }
  400. hr = HrRequestWizardPages(&pWizard, fPnpAddAdapter, rgpProviders,
  401. culProviders, phPages, &cPages, &sp, !fJumpToProviderPage);
  402. if ((S_OK != hr) || (0 == cPages))
  403. {
  404. goto Done;
  405. }
  406. ZeroMemory(&psh, sizeof(psh));
  407. psh.dwSize = sizeof(PROPSHEETHEADER);
  408. psh.dwFlags = PSH_WIZARD | PSH_WIZARD97 | PSH_NOAPPLYNOW | PSH_WATERMARK
  409. | PSH_HEADER | PSH_STRETCHWATERMARK | PSH_USECALLBACK | PSH_USEICONID;
  410. psh.hwndParent = hwnd;
  411. psh.hInstance = _Module.GetResourceInstance();
  412. psh.nPages = cPages;
  413. psh.phpage = phPages;
  414. psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WIZINTRO);
  415. psh.pszbmHeader = MAKEINTRESOURCE(IDB_WIZHDR);
  416. psh.pszIcon = MAKEINTRESOURCE(IDI_CONFOLD_WIZARD);
  417. psh.pfnCallback = HrSetWizardTaskbarIcon;
  418. if (pWizard->GetFirstPage())
  419. {
  420. if ( fJumpToProviderPage )
  421. {
  422. for (ULONG ulIdx = 0; ulIdx < pWizard->UlProviderCount(); ulIdx++)
  423. {
  424. CWizProvider * pWizProvider = pWizard->PWizProviders(ulIdx);
  425. Assert(NULL != pWizProvider);
  426. if (pWizard->GetFirstPage() == pWizProvider->GetBtnIdc())
  427. {
  428. pWizard->SetCurrentProvider(ulIdx);
  429. Assert(pWizProvider->ULPageCount());
  430. HPROPSHEETPAGE hPage = (pWizProvider->PHPropPages())[0];
  431. Assert(NULL != hPage);
  432. for (DWORD x = 0; x < cPages; x++)
  433. {
  434. if (phPages[x] == hPage)
  435. {
  436. psh.nStartPage = x;
  437. }
  438. }
  439. }
  440. }
  441. Assert(psh.nStartPage);
  442. }
  443. else
  444. {
  445. psh.nStartPage = pWizard->GetPageIndexFromIID(dwFirstPage);
  446. }
  447. }
  448. } // end the wait cursor
  449. // raise frame
  450. hr = S_FALSE;
  451. if (-1 != PropertySheet(&psh))
  452. {
  453. // Return the request connection
  454. if (ppConn && pWizard->GetCachedConnection())
  455. {
  456. *ppConn = pWizard->GetCachedConnection();
  457. AddRefObj(*ppConn);
  458. hr = S_OK;
  459. }
  460. }
  461. MemFree(phPages);
  462. Done:
  463. delete pWizard;
  464. TraceHr(ttidWizard, FAL, hr, (S_FALSE == hr), "CWizProvider::HrCreate");
  465. return hr;
  466. }
  467. VOID SetICWComplete()
  468. {
  469. static const TCHAR REG_KEY_ICW_SETTINGS[] = TEXT("Software\\Microsoft\\Internet Connection Wizard");
  470. static const TCHAR REG_VAL_ICWCOMPLETE[] = TEXT("Completed");
  471. HKEY hkey = NULL;
  472. DWORD dwValue = 1;
  473. DWORD dwDisposition = 0;
  474. if(ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER,
  475. REG_KEY_ICW_SETTINGS,
  476. 0,
  477. NULL,
  478. REG_OPTION_NON_VOLATILE,
  479. KEY_ALL_ACCESS,
  480. NULL,
  481. &hkey,
  482. &dwDisposition))
  483. {
  484. RegSetValueEx(hkey,
  485. REG_VAL_ICWCOMPLETE,
  486. 0,
  487. REG_BINARY,
  488. (LPBYTE) &dwValue,
  489. sizeof(DWORD));
  490. RegCloseKey(hkey);
  491. }
  492. }
  493. #include "foldinc.h"
  494. #include "..\folder\cmdtable.h"
  495. EXTERN_C INT WINAPI StartNCW( HWND hwndOwner, HINSTANCE hInstance, LPTSTR pszParms, INT nShow )
  496. {
  497. HRESULT hr = S_OK;
  498. vector<LPSTR> vecszCmdLine; // This is ANSI since our Command Line is ANSI.
  499. const CHAR szSeps[] = ",";
  500. LPSTR szToken = strtok( reinterpret_cast<LPSTR>(pszParms), szSeps);
  501. while( szToken != NULL )
  502. {
  503. vecszCmdLine.push_back(szToken);
  504. szToken = strtok( NULL, szSeps);
  505. }
  506. DWORD dwFirstPage = 0;
  507. LPSTR szShellNext = NULL;
  508. LPSTR szShellNextArg = NULL;
  509. if (vecszCmdLine.size() >= 1)
  510. {
  511. dwFirstPage = atoi(vecszCmdLine[0]);
  512. if (vecszCmdLine.size() >= 2)
  513. {
  514. szShellNext = vecszCmdLine[1];
  515. Assert(strlen(szShellNext) <= MAX_PATH); // Shell requirement
  516. if (vecszCmdLine.size() >= 3)
  517. {
  518. szShellNextArg = vecszCmdLine[2];
  519. Assert(strlen(szShellNextArg) <= MAX_PATH);
  520. }
  521. }
  522. }
  523. hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  524. if (SUCCEEDED(hr))
  525. {
  526. {
  527. // Check permissions
  528. PCONFOLDPIDLVEC pcfpvEmpty;
  529. NCCS_STATE nccs = NCCS_ENABLED;
  530. DWORD dwResourceId;
  531. HrGetCommandState(pcfpvEmpty, CMIDM_NEW_CONNECTION, nccs, &dwResourceId, 0xffffffff, NB_FLAG_ON_TOPMENU);
  532. if (NCCS_ENABLED == nccs)
  533. {
  534. CComPtr<INetConnection> pNetConn;
  535. // We don't send the owner handle to HrRunWizard,
  536. // so that the correct Alt-Tab icon can be displayed
  537. hr = HrRunWizard(NULL, FALSE , &pNetConn, dwFirstPage);
  538. }
  539. else
  540. {
  541. NcMsgBox(_Module.GetResourceInstance(),
  542. NULL,
  543. IDS_CONFOLD_WARNING_CAPTION,
  544. IDS_ERR_LIMITED_USER,
  545. MB_ICONEXCLAMATION | MB_OK);
  546. hr = S_OK;
  547. }
  548. SetICWComplete();
  549. if (szShellNext)
  550. {
  551. WCHAR szwShellNext[MAX_PATH];
  552. WCHAR szwShellNextArg[MAX_PATH];
  553. mbstowcs(szwShellNext, szShellNext, MAX_PATH);
  554. if (szShellNextArg)
  555. {
  556. mbstowcs(szwShellNextArg, szShellNextArg, MAX_PATH);
  557. }
  558. else
  559. {
  560. szwShellNextArg[0] = 0;
  561. }
  562. HINSTANCE hInst = ::ShellExecute(hwndOwner, NULL, szwShellNext, szwShellNextArg, NULL, nShow);
  563. if (hInst <= reinterpret_cast<HINSTANCE>(32))
  564. {
  565. hr = HRESULT_FROM_WIN32(static_cast<DWORD>(reinterpret_cast<DWORD_PTR>(hInst)));
  566. }
  567. }
  568. }
  569. CoUninitialize();
  570. }
  571. return hr;
  572. }