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.

1322 lines
36 KiB

  1. // Copyright (c) 2001 Microsoft Corporation
  2. //
  3. // File: ExpressRebootPage.cpp
  4. //
  5. // Synopsis: Defines the ExpressRebootPage that shows
  6. // the progress of the changes being made to
  7. // the server after the reboot fromt the
  8. // express path
  9. //
  10. // History: 05/11/2001 JeffJon Created
  11. #include "pch.h"
  12. #include "resource.h"
  13. #include "InstallationUnitProvider.h"
  14. #include "ExpressRebootPage.h"
  15. // Private window messages for updating the UI status
  16. // For these messages the WPARAM is the operation that finished, and
  17. // the LPARAM is the operation that is next
  18. const UINT ExpressRebootPage::CYS_OPERATION_FINISHED_SUCCESS = WM_USER + 1001;
  19. const UINT ExpressRebootPage::CYS_OPERATION_FINISHED_FAILED = WM_USER + 1002;
  20. const UINT ExpressRebootPage::CYS_OPERATION_COMPLETE_SUCCESS = WM_USER + 1003;
  21. const UINT ExpressRebootPage::CYS_OPERATION_COMPLETE_FAILED = WM_USER + 1004;
  22. // This structure maps the four static controls that make up an operation
  23. // together. The pageProgress array must be in the order the operations
  24. // will take place so that the page can update appropriately when
  25. // an CYS_OPERATION_FINISHED_* message is sent back to the page
  26. typedef struct _PageProgressStruct
  27. {
  28. unsigned int currentIconControl;
  29. unsigned int checkIconControl;
  30. unsigned int errorIconControl;
  31. unsigned int staticIconControl;
  32. } PageProgressStruct;
  33. PageProgressStruct pageOperationProgress[] =
  34. {
  35. {
  36. IDC_IPADDRESS_CURRENT_STATIC,
  37. IDC_IPADDRESS_CHECK_STATIC,
  38. IDC_IPADDRESS_ERROR_STATIC,
  39. IDC_IPADDRESS_STATIC
  40. },
  41. {
  42. IDC_DHCP_CURRENT_STATIC,
  43. IDC_DHCP_CHECK_STATIC,
  44. IDC_DHCP_ERROR_STATIC,
  45. IDC_DHCP_STATIC
  46. },
  47. {
  48. IDC_AD_CURRENT_STATIC,
  49. IDC_AD_CHECK_STATIC,
  50. IDC_AD_ERROR_STATIC,
  51. IDC_AD_STATIC
  52. },
  53. {
  54. IDC_DNS_CURRENT_STATIC,
  55. IDC_DNS_CHECK_STATIC,
  56. IDC_DNS_ERROR_STATIC,
  57. IDC_DNS_STATIC
  58. },
  59. {
  60. IDC_FORWARDER_CURRENT_STATIC,
  61. IDC_FORWARDER_CHECK_STATIC,
  62. IDC_FORWARDER_ERROR_STATIC,
  63. IDC_FORWARDER_STATIC
  64. },
  65. {
  66. IDC_DHCP_SCOPE_CURRENT_STATIC,
  67. IDC_DHCP_SCOPE_CHECK_STATIC,
  68. IDC_DHCP_SCOPE_ERROR_STATIC,
  69. IDC_DHCP_SCOPE_STATIC
  70. },
  71. {
  72. IDC_AUTHORIZE_SCOPE_CURRENT_STATIC,
  73. IDC_AUTHORIZE_SCOPE_CHECK_STATIC,
  74. IDC_AUTHORIZE_SCOPE_ERROR_STATIC,
  75. IDC_AUTHORIZE_SCOPE_STATIC
  76. },
  77. {
  78. IDC_TAPI_CURRENT_STATIC,
  79. IDC_TAPI_CHECK_STATIC,
  80. IDC_TAPI_ERROR_STATIC,
  81. IDC_TAPI_STATIC
  82. },
  83. { 0, 0, 0, 0 }
  84. };
  85. bool
  86. SetDNSForwarder(HANDLE logfileHandle)
  87. {
  88. LOG_FUNCTION(SetDNSForwarder);
  89. bool result = true;
  90. do
  91. {
  92. // First read the regky
  93. DWORD forwarder = 0;
  94. String autoForwarder;
  95. bool forwarderResult = GetRegKeyValue(
  96. CYS_FIRST_DC_REGKEY,
  97. CYS_FIRST_DC_FORWARDER,
  98. forwarder);
  99. bool autoForwarderResult = GetRegKeyValue(
  100. CYS_FIRST_DC_REGKEY,
  101. CYS_FIRST_DC_AUTOFORWARDER,
  102. autoForwarder);
  103. if (forwarderResult &&
  104. forwarder != 0)
  105. {
  106. DWORD forwarderInDisplayOrder = ConvertIPAddressOrder(forwarder);
  107. LOG(String::format(
  108. L"Setting forwarder from forwarder regkey: %1",
  109. IPAddressToString(forwarderInDisplayOrder).c_str()));
  110. DNS_STATUS error = ::DnssrvResetForwarders(
  111. L"localhost",
  112. 1,
  113. &forwarder,
  114. DNS_DEFAULT_FORWARD_TIMEOUT,
  115. DNS_DEFAULT_SLAVE);
  116. if (error != 0)
  117. {
  118. LOG(String::format(
  119. L"Failed to set the forwarder: error = 0x%1!x!",
  120. error));
  121. CYS_APPEND_LOG(String::load(IDS_EXPRESS_REBOOT_FORWARDER_FAILED));
  122. result = false;
  123. break;
  124. }
  125. CYS_APPEND_LOG(
  126. String::format(
  127. IDS_EXPRESS_REBOOT_FORWARDER_SUCCEEDED,
  128. IPAddressToString(forwarderInDisplayOrder).c_str()));
  129. }
  130. else if (autoForwarderResult &&
  131. !autoForwarder.empty())
  132. {
  133. LOG(String::format(
  134. L"Setting forwarder from autoforwarder regkey: %1",
  135. autoForwarder.c_str()));
  136. // Now parse the forwarders string into a DWORD array
  137. StringList forwardersList;
  138. autoForwarder.tokenize(std::back_inserter(forwardersList));
  139. DWORD count = 0;
  140. DWORD* forwarderArray = StringIPListToDWORDArray(forwardersList, count);
  141. if (forwarderArray)
  142. {
  143. DNS_STATUS error = ::DnssrvResetForwarders(
  144. L"localhost",
  145. count,
  146. forwarderArray,
  147. DNS_DEFAULT_FORWARD_TIMEOUT,
  148. DNS_DEFAULT_SLAVE);
  149. // Delete the memory returned from StringIPListToDWORDArray
  150. delete[] forwarderArray;
  151. forwarderArray = 0;
  152. // Check for errors
  153. if (error != 0)
  154. {
  155. LOG(String::format(
  156. L"Failed to set the forwarder: error = 0x%1!x!",
  157. error));
  158. CYS_APPEND_LOG(String::load(IDS_EXPRESS_REBOOT_FORWARDER_FAILED));
  159. result = false;
  160. break;
  161. }
  162. }
  163. }
  164. else
  165. {
  166. // Since the regkey wasn't set that means we should try
  167. // to take the forwarders from the NICs defined server list
  168. IPAddressList forwarders;
  169. InstallationUnitProvider::GetInstance().GetDNSInstallationUnit().GetForwarders(forwarders);
  170. if (forwarders.empty())
  171. {
  172. LOG(L"No DNS servers set on any NIC");
  173. CYS_APPEND_LOG(String::load(IDS_EXPRESS_REBOOT_FORWARDER_FAILED));
  174. result = false;
  175. break;
  176. }
  177. // This is an exception throwing new so there is no
  178. // reason to check for NULL
  179. DWORD forwardersCount = static_cast<DWORD>(forwarders.size());
  180. DWORD* forwardersArray = new DWORD[forwardersCount];
  181. // Copy the forwarders addresses into the array
  182. for (DWORD idx = 0; idx < forwardersCount; ++idx)
  183. {
  184. // The IP address must be in network order (d.c.b.a) not in the UI
  185. // order (a.b.c.d)
  186. forwardersArray[idx] = ConvertIPAddressOrder(forwarders[idx]);
  187. }
  188. // Now set the forwarders in the DNS server
  189. DNS_STATUS error = ::DnssrvResetForwarders(
  190. L"localhost",
  191. forwardersCount,
  192. forwardersArray,
  193. DNS_DEFAULT_FORWARD_TIMEOUT,
  194. DNS_DEFAULT_SLAVE);
  195. // Delete the allocated array
  196. delete[] forwardersArray;
  197. forwardersArray = 0;
  198. // Check for errors
  199. if (error != 0)
  200. {
  201. LOG(String::format(
  202. L"Failed to set the forwarders: error = 0x%1!x!",
  203. error));
  204. CYS_APPEND_LOG(String::load(IDS_EXPRESS_REBOOT_FORWARDER_FAILED));
  205. result = false;
  206. break;
  207. }
  208. CYS_APPEND_LOG(
  209. String::format(
  210. IDS_EXPRESS_REBOOT_FORWARDER_SUCCEEDED,
  211. IPAddressToString(ConvertIPAddressOrder(forwardersArray[0])).c_str()));
  212. }
  213. } while (false);
  214. LOG_BOOL(result);
  215. return result;
  216. }
  217. void _cdecl
  218. wrapperThreadProc(void* p)
  219. {
  220. if (!p)
  221. {
  222. ASSERT(p);
  223. return;
  224. }
  225. bool result = true;
  226. ExpressRebootPage* page =
  227. reinterpret_cast<ExpressRebootPage*>(p);
  228. ASSERT(page);
  229. HWND hwnd = page->GetHWND();
  230. // Create the log file
  231. bool logFileAvailable = false;
  232. String logName;
  233. HANDLE logfileHandle = AppendLogFile(
  234. CYS_LOGFILE_NAME,
  235. logName);
  236. if (logfileHandle &&
  237. logfileHandle != INVALID_HANDLE_VALUE)
  238. {
  239. LOG(String::format(L"New log file was created: %1", logName.c_str()));
  240. logFileAvailable = true;
  241. }
  242. else
  243. {
  244. LOG(L"Unable to create the log file!!!");
  245. logFileAvailable = false;
  246. }
  247. ExpressInstallationUnit& expressInstallationUnit =
  248. InstallationUnitProvider::GetInstance().GetExpressInstallationUnit();
  249. // NTRAID#NTBUG9-638337-2002/06/13-JeffJon
  250. // Need to compare the IP address that was written to the registry
  251. // to the current IP address to see if they are the same
  252. String currentIPAddress;
  253. NetworkInterface* localNIC =
  254. State::GetInstance().GetLocalNICFromRegistry();
  255. if (localNIC)
  256. {
  257. // Set the static text for the IP Address
  258. currentIPAddress =
  259. localNIC->GetStringIPAddress(0);
  260. }
  261. String attemptedIPAddress = page->GetIPAddressString();
  262. if (attemptedIPAddress.icompare(currentIPAddress) == 0)
  263. {
  264. LOG(L"The current IP address and the IP address from the registry match");
  265. Win::SendMessage(
  266. hwnd,
  267. ExpressRebootPage::CYS_OPERATION_FINISHED_SUCCESS,
  268. (WPARAM)ExpressRebootPage::CYS_OPERATION_SET_STATIC_IP,
  269. (LPARAM)ExpressRebootPage::CYS_OPERATION_SERVER_DHCP);
  270. }
  271. else
  272. {
  273. // Since the IP addresses didn't match we have to show the error
  274. // Most likely this was caused by another machine coming up on the
  275. // network with the same IP as we set before the reboot.
  276. LOG(L"Failed to set the static IP address.");
  277. Win::SendMessage(
  278. hwnd,
  279. ExpressRebootPage::CYS_OPERATION_FINISHED_FAILED,
  280. (WPARAM)ExpressRebootPage::CYS_OPERATION_SET_STATIC_IP,
  281. (LPARAM)ExpressRebootPage::CYS_OPERATION_SERVER_DHCP);
  282. }
  283. if (!page->WasDHCPInstallAttempted() ||
  284. InstallationUnitProvider::GetInstance().
  285. GetDHCPInstallationUnit().IsServiceInstalled())
  286. {
  287. Win::SendMessage(
  288. hwnd,
  289. ExpressRebootPage::CYS_OPERATION_FINISHED_SUCCESS,
  290. (WPARAM)ExpressRebootPage::CYS_OPERATION_SERVER_DHCP,
  291. (LPARAM)ExpressRebootPage::CYS_OPERATION_SERVER_AD);
  292. }
  293. else
  294. {
  295. Win::SendMessage(
  296. hwnd,
  297. ExpressRebootPage::CYS_OPERATION_FINISHED_FAILED,
  298. (WPARAM)ExpressRebootPage::CYS_OPERATION_SERVER_DHCP,
  299. (LPARAM)ExpressRebootPage::CYS_OPERATION_SERVER_AD);
  300. if (result)
  301. {
  302. expressInstallationUnit.SetExpressRoleResult(
  303. ExpressInstallationUnit::EXPRESS_DHCP_INSTALL_FAILURE);
  304. }
  305. result = false;
  306. }
  307. // Verify the machine is a DC
  308. // Check to see if DCPromo was successful in making this a DC
  309. if (State::GetInstance().IsDC())
  310. {
  311. CYS_APPEND_LOG(String::load(IDS_LOG_DCPROMO_REBOOT_SUCCEEDED));
  312. // Log the new domain name
  313. CYS_APPEND_LOG(String::load(IDS_EXPRESS_SERVER_AD));
  314. CYS_APPEND_LOG(
  315. String::format(
  316. IDS_EXPRESS_AD_DOMAIN_NAME,
  317. State::GetInstance().GetDomainDNSName().c_str()));
  318. CYS_APPEND_LOG(
  319. String::format(
  320. IDS_EXPRESS_AD_NETBIOS_NAME,
  321. State::GetInstance().GetDomainNetbiosName().c_str()));
  322. Win::SendMessage(
  323. hwnd,
  324. ExpressRebootPage::CYS_OPERATION_FINISHED_SUCCESS,
  325. (WPARAM)ExpressRebootPage::CYS_OPERATION_SERVER_AD,
  326. (LPARAM)ExpressRebootPage::CYS_OPERATION_SERVER_DNS);
  327. }
  328. else
  329. {
  330. LOG(L"DCPromo failed on reboot");
  331. CYS_APPEND_LOG(String::load(IDS_LOG_DCPROMO_REBOOT_FAILED));
  332. Win::SendMessage(
  333. hwnd,
  334. ExpressRebootPage::CYS_OPERATION_FINISHED_FAILED,
  335. (WPARAM)ExpressRebootPage::CYS_OPERATION_SERVER_AD,
  336. (LPARAM)ExpressRebootPage::CYS_OPERATION_SERVER_DNS);
  337. // Only override the role result if it hasn't already been set
  338. if (result)
  339. {
  340. expressInstallationUnit.SetExpressRoleResult(
  341. ExpressInstallationUnit::EXPRESS_AD_FAILURE);
  342. }
  343. result = false;
  344. }
  345. // DNS is now the current operation, check to see if it is installed
  346. if (InstallationUnitProvider::GetInstance().
  347. GetDNSInstallationUnit().IsServiceInstalled())
  348. {
  349. CYS_APPEND_LOG(String::load(IDS_EXPRESS_REBOOT_DNS_SERVER_SUCCEEDED));
  350. Win::SendMessage(
  351. hwnd,
  352. ExpressRebootPage::CYS_OPERATION_FINISHED_SUCCESS,
  353. (WPARAM)ExpressRebootPage::CYS_OPERATION_SERVER_DNS,
  354. (LPARAM)ExpressRebootPage::CYS_OPERATION_SET_DNS_FORWARDER);
  355. if (page->SetForwarder())
  356. {
  357. // Now wait for the service to start before trying to set the forwarders
  358. NTService serviceObject(CYS_DNS_SERVICE_NAME);
  359. HRESULT hr = serviceObject.WaitForServiceState(SERVICE_RUNNING);
  360. if (SUCCEEDED(hr))
  361. {
  362. if (SetDNSForwarder(logfileHandle))
  363. {
  364. Win::SendMessage(
  365. hwnd,
  366. ExpressRebootPage::CYS_OPERATION_FINISHED_SUCCESS,
  367. (WPARAM)ExpressRebootPage::CYS_OPERATION_SET_DNS_FORWARDER,
  368. (LPARAM)ExpressRebootPage::CYS_OPERATION_ACTIVATE_DHCP_SCOPE);
  369. }
  370. else
  371. {
  372. Win::SendMessage(
  373. hwnd,
  374. ExpressRebootPage::CYS_OPERATION_FINISHED_FAILED,
  375. (WPARAM)ExpressRebootPage::CYS_OPERATION_SET_DNS_FORWARDER,
  376. (LPARAM)ExpressRebootPage::CYS_OPERATION_ACTIVATE_DHCP_SCOPE);
  377. expressInstallationUnit.SetExpressRoleResult(
  378. ExpressInstallationUnit::EXPRESS_DNS_FORWARDER_FAILURE);
  379. result = false;
  380. }
  381. }
  382. else
  383. {
  384. LOG(L"The DNS service never started!");
  385. Win::SendMessage(
  386. hwnd,
  387. ExpressRebootPage::CYS_OPERATION_FINISHED_FAILED,
  388. (WPARAM)ExpressRebootPage::CYS_OPERATION_SET_DNS_FORWARDER,
  389. (LPARAM)ExpressRebootPage::CYS_OPERATION_ACTIVATE_DHCP_SCOPE);
  390. expressInstallationUnit.SetExpressRoleResult(
  391. ExpressInstallationUnit::EXPRESS_DNS_FORWARDER_FAILURE);
  392. result = false;
  393. }
  394. }
  395. else
  396. {
  397. CYS_APPEND_LOG(String::load(IDS_EXPRESS_REBOOT_LOG_NO_FORWARDER));
  398. Win::SendMessage(
  399. hwnd,
  400. ExpressRebootPage::CYS_OPERATION_FINISHED_SUCCESS,
  401. (WPARAM)ExpressRebootPage::CYS_OPERATION_SET_DNS_FORWARDER,
  402. (LPARAM)ExpressRebootPage::CYS_OPERATION_ACTIVATE_DHCP_SCOPE);
  403. }
  404. }
  405. else
  406. {
  407. CYS_APPEND_LOG(String::load(IDS_EXPRESS_REBOOT_DNS_SERVER_FAILED));
  408. Win::SendMessage(
  409. hwnd,
  410. ExpressRebootPage::CYS_OPERATION_FINISHED_FAILED,
  411. (WPARAM)ExpressRebootPage::CYS_OPERATION_SERVER_DNS,
  412. (LPARAM)ExpressRebootPage::CYS_OPERATION_SET_DNS_FORWARDER);
  413. // If the DNS service isn't installed there is no way to set a
  414. // forwarder
  415. Win::SendMessage(
  416. hwnd,
  417. ExpressRebootPage::CYS_OPERATION_FINISHED_FAILED,
  418. (WPARAM)ExpressRebootPage::CYS_OPERATION_SET_DNS_FORWARDER,
  419. (LPARAM)ExpressRebootPage::CYS_OPERATION_ACTIVATE_DHCP_SCOPE);
  420. // Only override the role result if it hasn't already been set
  421. if (result)
  422. {
  423. expressInstallationUnit.SetExpressRoleResult(
  424. ExpressInstallationUnit::EXPRESS_DNS_SERVER_FAILURE);
  425. }
  426. result = false;
  427. }
  428. // Verify DHCP scope activation
  429. Win::SendMessage(
  430. hwnd,
  431. ExpressRebootPage::CYS_OPERATION_FINISHED_SUCCESS,
  432. (WPARAM)ExpressRebootPage::CYS_OPERATION_ACTIVATE_DHCP_SCOPE,
  433. (LPARAM)ExpressRebootPage::CYS_OPERATION_AUTHORIZE_DHCP_SERVER);
  434. // Authorize the DHCP server
  435. String dnsName = Win::GetComputerNameEx(ComputerNameDnsFullyQualified);
  436. if (page->WasDHCPInstallAttempted())
  437. {
  438. if (InstallationUnitProvider::GetInstance().GetDHCPInstallationUnit().AuthorizeDHCPServer(dnsName))
  439. {
  440. LOG(L"DHCP server successfully authorized");
  441. CYS_APPEND_LOG(String::load(IDS_LOG_DHCP_AUTHORIZATION_SUCCEEDED));
  442. Win::SendMessage(
  443. hwnd,
  444. ExpressRebootPage::CYS_OPERATION_FINISHED_SUCCESS,
  445. (WPARAM)ExpressRebootPage::CYS_OPERATION_AUTHORIZE_DHCP_SERVER,
  446. (LPARAM)ExpressRebootPage::CYS_OPERATION_CREATE_TAPI_PARTITION);
  447. }
  448. else
  449. {
  450. LOG(L"DHCP scope authorization failed");
  451. String failureMessage = String::load(IDS_LOG_DHCP_AUTHORIZATION_FAILED);
  452. CYS_APPEND_LOG(failureMessage);
  453. Win::SendMessage(
  454. hwnd,
  455. ExpressRebootPage::CYS_OPERATION_FINISHED_FAILED,
  456. (WPARAM)ExpressRebootPage::CYS_OPERATION_AUTHORIZE_DHCP_SERVER,
  457. (LPARAM)ExpressRebootPage::CYS_OPERATION_CREATE_TAPI_PARTITION);
  458. // Only override the role result if it hasn't already been set
  459. if (result)
  460. {
  461. expressInstallationUnit.SetExpressRoleResult(
  462. ExpressInstallationUnit::EXPRESS_DHCP_ACTIVATION_FAILURE);
  463. }
  464. result = false;
  465. }
  466. }
  467. else
  468. {
  469. Win::SendMessage(
  470. hwnd,
  471. ExpressRebootPage::CYS_OPERATION_FINISHED_SUCCESS,
  472. (WPARAM)ExpressRebootPage::CYS_OPERATION_AUTHORIZE_DHCP_SERVER,
  473. (LPARAM)ExpressRebootPage::CYS_OPERATION_CREATE_TAPI_PARTITION);
  474. }
  475. // Do TAPI config
  476. HRESULT hr =
  477. InstallationUnitProvider::GetInstance().
  478. GetExpressInstallationUnit().DoTapiConfig(
  479. State::GetInstance().GetDomainDNSName());
  480. if (SUCCEEDED(hr))
  481. {
  482. LOG(L"TAPI config succeeded");
  483. CYS_APPEND_LOG(String::load(IDS_LOG_TAPI_CONFIG_SUCCEEDED));
  484. CYS_APPEND_LOG(
  485. String::format(
  486. IDS_LOG_TAPI_CONFIG_SUCCEEDED_FORMAT,
  487. dnsName.c_str()));
  488. Win::SendMessage(
  489. hwnd,
  490. ExpressRebootPage::CYS_OPERATION_FINISHED_SUCCESS,
  491. (WPARAM)ExpressRebootPage::CYS_OPERATION_CREATE_TAPI_PARTITION,
  492. (LPARAM)ExpressRebootPage::CYS_OPERATION_END);
  493. }
  494. else
  495. {
  496. LOG(L"TAPI config failed");
  497. CYS_APPEND_LOG(
  498. String::format(
  499. IDS_LOG_TAPI_CONFIG_FAILED_FORMAT,
  500. hr));
  501. Win::SendMessage(
  502. hwnd,
  503. ExpressRebootPage::CYS_OPERATION_FINISHED_FAILED,
  504. (WPARAM)ExpressRebootPage::CYS_OPERATION_CREATE_TAPI_PARTITION,
  505. (LPARAM)ExpressRebootPage::CYS_OPERATION_END);
  506. // Only override the role result if it hasn't already been set
  507. if (result)
  508. {
  509. expressInstallationUnit.SetExpressRoleResult(
  510. ExpressInstallationUnit::EXPRESS_TAPI_FAILURE);
  511. }
  512. result = false;
  513. }
  514. // Close the log file
  515. Win::CloseHandle(logfileHandle);
  516. if (result)
  517. {
  518. Win::SendMessage(
  519. hwnd,
  520. ExpressRebootPage::CYS_OPERATION_COMPLETE_SUCCESS,
  521. 0,
  522. 0);
  523. }
  524. else
  525. {
  526. Win::SendMessage(
  527. hwnd,
  528. ExpressRebootPage::CYS_OPERATION_COMPLETE_FAILED,
  529. 0,
  530. 0);
  531. }
  532. }
  533. static PCWSTR EXPRESS_REBOOT_PAGE_HELP = L"cys.chm::/typical_setup.htm";
  534. ExpressRebootPage::ExpressRebootPage()
  535. :
  536. dhcpInstallAttempted(true),
  537. setForwarder(true),
  538. threadDone(false),
  539. CYSWizardPage(
  540. IDD_EXPRESS_REBOOT_PAGE,
  541. IDS_EXPRESS_REBOOT_TITLE,
  542. IDS_EXPRESS_REBOOT_SUBTITLE,
  543. EXPRESS_REBOOT_PAGE_HELP)
  544. {
  545. LOG_CTOR(ExpressRebootPage);
  546. }
  547. ExpressRebootPage::~ExpressRebootPage()
  548. {
  549. LOG_DTOR(ExpressRebootPage);
  550. }
  551. void
  552. ExpressRebootPage::OnInit()
  553. {
  554. LOG_FUNCTION(ExpressRebootPage::OnInit);
  555. CYSWizardPage::OnInit();
  556. // Since this page can be started directly
  557. // we have to be sure to set the wizard title
  558. Win::PropSheet_SetTitle(
  559. Win::GetParent(hwnd),
  560. 0,
  561. String::load(IDS_WIZARD_TITLE));
  562. ClearOperationStates();
  563. Win::ShowWindow(
  564. Win::GetDlgItem(
  565. hwnd,
  566. IDC_EXPRESS_CONFIG_DONE_STATIC),
  567. false);
  568. // Set the range and step size for the progress bar
  569. Win::SendMessage(
  570. Win::GetDlgItem(hwnd, IDC_CONFIG_PROGRESS),
  571. PBM_SETRANGE,
  572. 0,
  573. MAKELPARAM(CYS_OPERATION_SET_STATIC_IP, CYS_OPERATION_END));
  574. Win::SendMessage(
  575. Win::GetDlgItem(hwnd, IDC_CONFIG_PROGRESS),
  576. PBM_SETSTEP,
  577. (WPARAM)1,
  578. 0);
  579. // Set the state object so that CYS doesn't run again
  580. // State::GetInstance().SetRerunWizard(false);
  581. // Initialize the state object so we can get the info to put
  582. // in the UI
  583. State::GetInstance().RetrieveMachineConfigurationInformation(
  584. 0,
  585. false,
  586. IDS_RETRIEVE_NIC_INFO,
  587. IDS_RETRIEVE_OS_INFO,
  588. IDS_LOCAL_AREA_CONNECTION,
  589. IDS_DETECTING_SETTINGS_FORMAT);
  590. // NTRAID#NTBUG9-638337-2002/06/13-JeffJon
  591. // We need to display the IP address that was written to the
  592. // registry before the reboot because the "local NIC" IP
  593. // address may have been changed if a machine was brought
  594. // up on the network with a duplicate IP address while we
  595. // were rebooting.
  596. if (!GetRegKeyValue(
  597. CYS_FIRST_DC_REGKEY,
  598. CYS_FIRST_DC_STATIC_IP,
  599. ipaddressString,
  600. HKEY_LOCAL_MACHINE))
  601. {
  602. LOG(L"Failed to read the regkey for the static IP address.");
  603. }
  604. String ipaddressStaticText = String::format(
  605. IDS_EXPRESS_REBOOT_IPADDRESS,
  606. ipaddressString.c_str());
  607. Win::SetDlgItemText(
  608. hwnd,
  609. IDC_IPADDRESS_STATIC,
  610. ipaddressStaticText);
  611. // Set the static text for the DNS Forwarder
  612. String forwarderStaticText;
  613. String autoForwardersText;
  614. DWORD forwarder = 0;
  615. bool forwarderResult = GetRegKeyValue(
  616. CYS_FIRST_DC_REGKEY,
  617. CYS_FIRST_DC_FORWARDER,
  618. forwarder);
  619. bool autoForwarderResult = GetRegKeyValue(
  620. CYS_FIRST_DC_REGKEY,
  621. CYS_FIRST_DC_AUTOFORWARDER,
  622. autoForwardersText);
  623. if (forwarderResult)
  624. {
  625. // We were able to read the fowarder regkey so the user
  626. // must have seen the DNS Forwarder page before the reboot
  627. if (forwarder != 0)
  628. {
  629. // The user entered an IP address on the DNS Forwarder page
  630. // before the reboot
  631. DWORD forwarderInDisplayOrder = ConvertIPAddressOrder(forwarder);
  632. forwarderStaticText = String::format(
  633. IDS_EXPRESS_REBOOT_FORWARDER,
  634. IPAddressToString(forwarderInDisplayOrder).c_str());
  635. LOG(String::format(
  636. L"Read forwarders from forwarder key: %1",
  637. forwarderStaticText.c_str()));
  638. }
  639. else
  640. {
  641. // The user chose not to forward when prompted on the DNS Forwarder
  642. // page before the reboot
  643. forwarderStaticText = String::load(IDS_EXPRESS_REBOOT_NO_FORWARDER);
  644. setForwarder = false;
  645. }
  646. }
  647. else if (autoForwarderResult &&
  648. !autoForwardersText.empty())
  649. {
  650. forwarderStaticText = String::format(
  651. IDS_EXPRESS_REBOOT_FORWARDER,
  652. autoForwardersText.c_str());
  653. LOG(String::format(
  654. L"Read forwarders from autoforwarder key: %1",
  655. autoForwardersText.c_str()));
  656. }
  657. else
  658. {
  659. LOG(L"Failed to read both the forwarders and autoforwarders key, using local NIC settings instead");
  660. // Get the DNS servers from the NICs
  661. IPAddressList forwarders;
  662. InstallationUnitProvider::GetInstance().GetDNSInstallationUnit().GetForwarders(forwarders);
  663. if (!forwarders.empty())
  664. {
  665. // Format the IP addresses into a string for display
  666. // each IP address is separated by a space
  667. String ipList;
  668. for (IPAddressList::iterator itr = forwarders.begin();
  669. itr != forwarders.end();
  670. ++itr)
  671. {
  672. if (!ipList.empty())
  673. {
  674. ipList += L" ";
  675. }
  676. ipList += String::format(
  677. L"%1",
  678. IPAddressToString(*itr).c_str());
  679. }
  680. forwarderStaticText = String::format(
  681. IDS_EXPRESS_REBOOT_FORWARDER,
  682. ipList.c_str());
  683. }
  684. else
  685. {
  686. forwarderStaticText = String::load(IDS_EXPRESS_REBOOT_NO_FORWARDER);
  687. setForwarder = false;
  688. }
  689. }
  690. Win::SetDlgItemText(
  691. hwnd,
  692. IDC_FORWARDER_STATIC,
  693. forwarderStaticText);
  694. SetDHCPStatics();
  695. // Start up another thread that will perform the operations
  696. // and post messages back to the page to update the UI
  697. _beginthread(wrapperThreadProc, 0, this);
  698. }
  699. bool
  700. ExpressRebootPage::OnSetActive()
  701. {
  702. LOG_FUNCTION(ExpressRebootPage::OnSetActive);
  703. // Disable all the wizard buttons until the other
  704. // thread is finished
  705. if (threadDone)
  706. {
  707. Win::PropSheet_SetWizButtons(
  708. Win::GetParent(hwnd),
  709. PSWIZB_NEXT);
  710. }
  711. else
  712. {
  713. Win::PropSheet_SetWizButtons(
  714. Win::GetParent(hwnd),
  715. 0);
  716. }
  717. // Disable the cancel button and the X in the upper
  718. // right corner
  719. SetCancelState(false);
  720. return true;
  721. }
  722. void
  723. ExpressRebootPage::SetCancelState(bool enable) const
  724. {
  725. LOG_FUNCTION(ExpressRebootPage::SetCancelState);
  726. // Set the state of the button
  727. Win::EnableWindow(
  728. Win::GetDlgItem(
  729. Win::GetParent(hwnd),
  730. IDCANCEL),
  731. enable);
  732. // Set the state of the X in the upper right corner
  733. HMENU menu = GetSystemMenu(GetParent(hwnd), FALSE);
  734. if (menu)
  735. {
  736. if (enable)
  737. {
  738. EnableMenuItem(
  739. menu,
  740. SC_CLOSE,
  741. MF_BYCOMMAND | MF_ENABLED);
  742. }
  743. else
  744. {
  745. EnableMenuItem(
  746. menu,
  747. SC_CLOSE,
  748. MF_BYCOMMAND | MF_GRAYED);
  749. }
  750. }
  751. }
  752. void
  753. ExpressRebootPage::SetDHCPStatics()
  754. {
  755. LOG_FUNCTION(ExpressRebootPage::SetDHCPStatics);
  756. DWORD dhcpInstalled = 0;
  757. bool regResult = GetRegKeyValue(
  758. CYS_FIRST_DC_REGKEY,
  759. CYS_FIRST_DC_DHCP_SERVERED,
  760. dhcpInstalled,
  761. HKEY_LOCAL_MACHINE);
  762. if (regResult && !dhcpInstalled)
  763. {
  764. dhcpInstallAttempted = false;
  765. // Set the static text so that users know we didn't install DHCP
  766. Win::SetDlgItemText(
  767. hwnd,
  768. IDC_DHCP_STATIC,
  769. String::load(IDS_EXPRESS_DHCP_NOT_REQUIRED));
  770. Win::SetDlgItemText(
  771. hwnd,
  772. IDC_DHCP_SCOPE_STATIC,
  773. String::load(IDS_EXPRESS_DHCP_SCOPE_NONE));
  774. Win::SetDlgItemText(
  775. hwnd,
  776. IDC_AUTHORIZE_SCOPE_STATIC,
  777. String::load(IDS_EXPRESS_DHCP_NO_AUTHORIZATION));
  778. }
  779. else
  780. {
  781. dhcpInstallAttempted = true;
  782. // Set the static text for the DHCP scopes to authorize
  783. String start;
  784. if (!GetRegKeyValue(
  785. CYS_FIRST_DC_REGKEY,
  786. CYS_FIRST_DC_SCOPE_START,
  787. start))
  788. {
  789. LOG(L"Failed to get the start scope regkey");
  790. }
  791. String end;
  792. if (!GetRegKeyValue(
  793. CYS_FIRST_DC_REGKEY,
  794. CYS_FIRST_DC_SCOPE_END,
  795. end))
  796. {
  797. LOG(L"Failed to get the end scope regkey");
  798. }
  799. String authorizedScopesText = String::format(
  800. IDS_EXPRESS_REBOOT_DHCP_SCOPE,
  801. start.c_str(),
  802. end.c_str());
  803. Win::SetDlgItemText(
  804. hwnd,
  805. IDC_DHCP_SCOPE_STATIC,
  806. authorizedScopesText);
  807. }
  808. }
  809. bool
  810. ExpressRebootPage::OnMessage(
  811. UINT message,
  812. WPARAM wparam,
  813. LPARAM lparam)
  814. {
  815. // LOG_FUNCTION(ExpressRebootPage::OnMessage);
  816. bool result = false;
  817. CYS_OPERATION_TYPES finishedOperation = static_cast<CYS_OPERATION_TYPES>(wparam);
  818. CYS_OPERATION_TYPES nextOperation = static_cast<CYS_OPERATION_TYPES>(lparam);
  819. switch (message)
  820. {
  821. case CYS_OPERATION_FINISHED_SUCCESS:
  822. SetOperationState(
  823. OPERATION_STATE_FINISHED_SUCCESS,
  824. finishedOperation,
  825. nextOperation);
  826. result = true;
  827. break;
  828. case CYS_OPERATION_FINISHED_FAILED:
  829. SetOperationState(
  830. OPERATION_STATE_FINISHED_FAILED,
  831. finishedOperation,
  832. nextOperation);
  833. result = true;
  834. break;
  835. case CYS_OPERATION_COMPLETE_SUCCESS:
  836. {
  837. // enable the Next button
  838. Win::PropSheet_SetWizButtons(
  839. Win::GetParent(hwnd),
  840. PSWIZB_NEXT);
  841. Win::ShowWindow(
  842. Win::GetDlgItem(
  843. hwnd,
  844. IDC_EXPRESS_CONFIG_DONE_STATIC),
  845. true);
  846. result = true;
  847. threadDone = true;
  848. InstallationUnitProvider::GetInstance().
  849. GetExpressInstallationUnit().SetInstallResult(INSTALL_SUCCESS);
  850. }
  851. break;
  852. case CYS_OPERATION_COMPLETE_FAILED:
  853. {
  854. // enable the Next button
  855. Win::PropSheet_SetWizButtons(
  856. Win::GetParent(hwnd),
  857. PSWIZB_NEXT);
  858. Win::ShowWindow(
  859. Win::GetDlgItem(
  860. hwnd,
  861. IDC_EXPRESS_CONFIG_DONE_STATIC),
  862. true);
  863. result = true;
  864. threadDone = true;
  865. InstallationUnitProvider::GetInstance().
  866. GetExpressInstallationUnit().SetInstallResult(INSTALL_FAILURE);
  867. }
  868. break;
  869. default:
  870. result =
  871. CYSWizardPage::OnMessage(
  872. message,
  873. wparam,
  874. lparam);
  875. break;
  876. }
  877. return result;
  878. }
  879. void
  880. ExpressRebootPage::SetOperationState(
  881. OperationStateType state,
  882. CYS_OPERATION_TYPES currentOperation,
  883. CYS_OPERATION_TYPES nextOperation)
  884. {
  885. LOG_FUNCTION(ExpressRebootPage::SetOperationState);
  886. switch (state)
  887. {
  888. case OPERATION_STATE_UNKNOWN:
  889. if (currentOperation < CYS_OPERATION_END)
  890. {
  891. Win::ShowWindow(
  892. Win::GetDlgItem(
  893. hwnd,
  894. pageOperationProgress[currentOperation].currentIconControl),
  895. SW_HIDE);
  896. Win::ShowWindow(
  897. Win::GetDlgItem(
  898. hwnd,
  899. pageOperationProgress[currentOperation].checkIconControl),
  900. SW_HIDE);
  901. Win::ShowWindow(
  902. Win::GetDlgItem(
  903. hwnd,
  904. pageOperationProgress[currentOperation].errorIconControl),
  905. SW_HIDE);
  906. }
  907. if (nextOperation < CYS_OPERATION_END)
  908. {
  909. Win::ShowWindow(
  910. Win::GetDlgItem(
  911. hwnd,
  912. pageOperationProgress[nextOperation].currentIconControl),
  913. SW_HIDE);
  914. Win::ShowWindow(
  915. Win::GetDlgItem(
  916. hwnd,
  917. pageOperationProgress[nextOperation].checkIconControl),
  918. SW_HIDE);
  919. Win::ShowWindow(
  920. Win::GetDlgItem(
  921. hwnd,
  922. pageOperationProgress[nextOperation].errorIconControl),
  923. SW_HIDE);
  924. }
  925. break;
  926. case OPERATION_STATE_FINISHED_SUCCESS:
  927. if (currentOperation < CYS_OPERATION_END)
  928. {
  929. Win::ShowWindow(
  930. Win::GetDlgItem(
  931. hwnd,
  932. pageOperationProgress[currentOperation].currentIconControl),
  933. SW_HIDE);
  934. Win::ShowWindow(
  935. Win::GetDlgItem(
  936. hwnd,
  937. pageOperationProgress[currentOperation].errorIconControl),
  938. SW_HIDE);
  939. Win::ShowWindow(
  940. Win::GetDlgItem(
  941. hwnd,
  942. pageOperationProgress[currentOperation].checkIconControl),
  943. SW_SHOW);
  944. }
  945. if (nextOperation < CYS_OPERATION_END)
  946. {
  947. Win::ShowWindow(
  948. Win::GetDlgItem(
  949. hwnd,
  950. pageOperationProgress[nextOperation].checkIconControl),
  951. SW_HIDE);
  952. Win::ShowWindow(
  953. Win::GetDlgItem(
  954. hwnd,
  955. pageOperationProgress[nextOperation].errorIconControl),
  956. SW_HIDE);
  957. Win::ShowWindow(
  958. Win::GetDlgItem(
  959. hwnd,
  960. pageOperationProgress[nextOperation].currentIconControl),
  961. SW_SHOW);
  962. }
  963. // Update the progress bar
  964. Win::SendMessage(
  965. Win::GetDlgItem(hwnd, IDC_CONFIG_PROGRESS),
  966. PBM_STEPIT,
  967. 0,
  968. 0);
  969. break;
  970. case OPERATION_STATE_FINISHED_FAILED:
  971. if (currentOperation < CYS_OPERATION_END)
  972. {
  973. Win::ShowWindow(
  974. Win::GetDlgItem(
  975. hwnd,
  976. pageOperationProgress[currentOperation].currentIconControl),
  977. SW_HIDE);
  978. Win::ShowWindow(
  979. Win::GetDlgItem(
  980. hwnd,
  981. pageOperationProgress[currentOperation].checkIconControl),
  982. SW_HIDE);
  983. Win::ShowWindow(
  984. Win::GetDlgItem(
  985. hwnd,
  986. pageOperationProgress[currentOperation].errorIconControl),
  987. SW_SHOW);
  988. }
  989. if (nextOperation < CYS_OPERATION_END)
  990. {
  991. Win::ShowWindow(
  992. Win::GetDlgItem(
  993. hwnd,
  994. pageOperationProgress[nextOperation].checkIconControl),
  995. SW_HIDE);
  996. Win::ShowWindow(
  997. Win::GetDlgItem(
  998. hwnd,
  999. pageOperationProgress[nextOperation].errorIconControl),
  1000. SW_HIDE);
  1001. Win::ShowWindow(
  1002. Win::GetDlgItem(
  1003. hwnd,
  1004. pageOperationProgress[nextOperation].currentIconControl),
  1005. SW_SHOW);
  1006. }
  1007. // Update the progress bar
  1008. Win::SendMessage(
  1009. Win::GetDlgItem(hwnd, IDC_CONFIG_PROGRESS),
  1010. PBM_STEPIT,
  1011. 0,
  1012. 0);
  1013. break;
  1014. default:
  1015. // Right now I am not handling the CYS_OPERATION_COMPLETED_* messages
  1016. break;
  1017. }
  1018. }
  1019. void
  1020. ExpressRebootPage::ClearOperationStates()
  1021. {
  1022. LOG_FUNCTION(ExpressRebootPage::ClearOperationStates);
  1023. SetOperationState(
  1024. OPERATION_STATE_UNKNOWN,
  1025. CYS_OPERATION_SET_STATIC_IP,
  1026. CYS_OPERATION_SERVER_DHCP);
  1027. SetOperationState(
  1028. OPERATION_STATE_UNKNOWN,
  1029. CYS_OPERATION_SERVER_AD,
  1030. CYS_OPERATION_SERVER_DNS);
  1031. SetOperationState(
  1032. OPERATION_STATE_UNKNOWN,
  1033. CYS_OPERATION_SET_DNS_FORWARDER,
  1034. CYS_OPERATION_ACTIVATE_DHCP_SCOPE);
  1035. SetOperationState(
  1036. OPERATION_STATE_UNKNOWN,
  1037. CYS_OPERATION_AUTHORIZE_DHCP_SERVER,
  1038. CYS_OPERATION_CREATE_TAPI_PARTITION);
  1039. }
  1040. int
  1041. ExpressRebootPage::Validate()
  1042. {
  1043. LOG_FUNCTION(ExpressRebootPage::Validate);
  1044. int nextPage = IDD_FINISH_PAGE;
  1045. return nextPage;
  1046. }
  1047. String
  1048. ExpressRebootPage::GetIPAddressString() const
  1049. {
  1050. LOG_FUNCTION(ExpressRebootPage::GetIPAddressString);
  1051. String result = ipaddressString;
  1052. LOG(result);
  1053. return result;
  1054. }