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.

1292 lines
34 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*
  3. *
  4. * State.cpp
  5. *
  6. * Routines to gather various state information.
  7. *
  8. */
  9. //
  10. // Includes
  11. //
  12. #define _STATE_CPP_
  13. #include "stdafx.h"
  14. #include "hydraoc.h"
  15. // local functions
  16. BOOL ReadStringFromAnsewerFile (LPTSTR *szValue);
  17. BOOL ReadIntFromAnswerFile(LPCTSTR szSection, LPCTSTR szKey, int *piValue);
  18. BOOL GetAllowConnectionFromAnswerFile (BOOL *pbAllowConnection);
  19. BOOL GetPermissionsSettingsFromUnAttendedFile (EPermMode *pPermMode );
  20. BOOL GetAppModeFromAnswerFile (BOOL *pbEnableAppCompat);
  21. // global state object.
  22. TSState StateObject;
  23. //
  24. // OC State Function Definitions
  25. //
  26. BOOL DoesTSAppCompatKeyExist( VOID )
  27. {
  28. return TRUE;
  29. }
  30. BOOL ReadIntFromAnswerFile(LPCTSTR szSection, LPCTSTR szKey, int *piValue)
  31. {
  32. ASSERT(szSection);
  33. ASSERT(szKey);
  34. ASSERT(piValue);
  35. HINF hInf = GetUnAttendedInfHandle();
  36. if (hInf)
  37. {
  38. INFCONTEXT InfContext;
  39. if (SetupFindFirstLine( hInf, szSection, szKey, &InfContext))
  40. {
  41. return SetupGetIntField( &InfContext, 1, piValue );
  42. }
  43. }
  44. return FALSE;
  45. }
  46. BOOL ReadStringFromAnsewerFile (LPCTSTR szSection, LPCTSTR szKey, LPTSTR szValue, DWORD dwBufferSize)
  47. {
  48. ASSERT(szSection);
  49. ASSERT(szKey);
  50. ASSERT(szValue);
  51. ASSERT(dwBufferSize > 0);
  52. HINF hInf = GetUnAttendedInfHandle();
  53. if (hInf)
  54. {
  55. INFCONTEXT InfContext;
  56. if (SetupFindFirstLine(hInf, szSection, szKey, &InfContext))
  57. {
  58. return SetupGetStringField (&InfContext, 1, szValue, dwBufferSize, NULL);
  59. }
  60. }
  61. return FALSE;
  62. }
  63. BOOL GetAllowConnectionFromAnswerFile (BOOL *pbAllowConnection)
  64. {
  65. ASSERT(pbAllowConnection);
  66. int iValue;
  67. if (ReadIntFromAnswerFile(TS_UNATTEND_SECTION, TS_ALLOW_CON_ENTRY, &iValue))
  68. {
  69. LOGMESSAGE2(_T("Found %s in unattended, Value = %d"), TS_ALLOW_CON_ENTRY, iValue);
  70. if (iValue == 1)
  71. {
  72. *pbAllowConnection = TRUE;
  73. }
  74. else if (iValue == 0)
  75. {
  76. *pbAllowConnection = FALSE;
  77. }
  78. else
  79. {
  80. LOGMESSAGE2(_T("ERROR, Invalid value for %s (%d)in answer file. Ignoring..."), TS_ALLOW_CON_ENTRY, iValue);
  81. return FALSE;
  82. }
  83. return TRUE;
  84. }
  85. else
  86. {
  87. //
  88. // if we did not find TS_ALLOW_CON_ENTRY in answer file, then look for TS_ALLOW_CON_ENTRY_2
  89. if (ReadIntFromAnswerFile(TS_UNATTEND_SECTION, TS_ALLOW_CON_ENTRY_2, &iValue))
  90. {
  91. LOGMESSAGE2(_T("Found %s in unattended, Value = %d"), TS_ALLOW_CON_ENTRY_2, iValue);
  92. if (iValue == 1)
  93. {
  94. *pbAllowConnection = TRUE;
  95. }
  96. else if (iValue == 0)
  97. {
  98. *pbAllowConnection = FALSE;
  99. }
  100. else
  101. {
  102. LOGMESSAGE2(_T("ERROR, Invalid value for %s (%d)in answer file. Ignoring..."), TS_ALLOW_CON_ENTRY_2, iValue);
  103. return FALSE;
  104. }
  105. return TRUE;
  106. }
  107. }
  108. LOGMESSAGE0(_T("answer file entry for allowconnection not found"));
  109. return FALSE;
  110. }
  111. BOOL GetAppModeFromAnswerFile (BOOL *pbEnableAppCompat)
  112. {
  113. ASSERT(pbEnableAppCompat);
  114. TCHAR szBuffer[256];
  115. if (ReadStringFromAnsewerFile(_T("Components"), APPSRV_COMPONENT_NAME, szBuffer, 256))
  116. {
  117. ASSERT(szBuffer);
  118. if (0 == _tcsicmp(_T("on"), szBuffer))
  119. {
  120. *pbEnableAppCompat = TRUE;
  121. }
  122. else if (0 == _tcsicmp(_T("off"), szBuffer))
  123. {
  124. *pbEnableAppCompat = FALSE;
  125. }
  126. else
  127. {
  128. LOGMESSAGE2(_T("ERROR, Invalid value for %s (%s) in answer file. Ignoring..."), APPSRV_COMPONENT_NAME, szBuffer);
  129. return FALSE;
  130. }
  131. return TRUE;
  132. }
  133. else
  134. {
  135. return FALSE;
  136. }
  137. }
  138. ETSLicensingMode GetLicensingModeFromAnswerFile()
  139. {
  140. TCHAR szBuffer[256];
  141. if (ReadStringFromAnsewerFile(TS_UNATTEND_SECTION, TS_LICENSING_MODE, szBuffer, 256))
  142. {
  143. if (0 == _tcsicmp(_T("perdevice"), szBuffer))
  144. {
  145. return eLicPerDevice;
  146. }
  147. else if (0 == _tcsicmp(_T("persession"), szBuffer))
  148. {
  149. LOGMESSAGE2(_T("ERROR, Invalid value for %s (%s) in answer file. Defaulting to PerUser..."), TS_UNATTEND_SECTION, szBuffer);
  150. return eLicPerUser;
  151. }
  152. else if (0 == _tcsicmp(_T("peruser"), szBuffer))
  153. {
  154. return eLicPerUser;
  155. }
  156. else if (0 == _tcsicmp(_T("pts"), szBuffer))
  157. {
  158. return eLicPTS;
  159. }
  160. else if (0 == _tcsicmp(_T("remoteadmin"), szBuffer))
  161. {
  162. return eLicRemoteAdmin;
  163. }
  164. else if (0 == _tcsicmp(_T("internetconnector"), szBuffer))
  165. {
  166. return eLicInternetConnector;
  167. }
  168. else
  169. {
  170. LOGMESSAGE2(_T("ERROR, Invalid value for %s (%s) in answer file. Ignoring..."), TS_UNATTEND_SECTION, szBuffer);
  171. return eLicUnset;
  172. }
  173. }
  174. else
  175. {
  176. return eLicUnset;
  177. }
  178. }
  179. BOOL GetPermissionsSettingsFromUnAttendedFile( EPermMode *pPermMode )
  180. {
  181. ASSERT(pPermMode);
  182. int iValue;
  183. if (ReadIntFromAnswerFile(TS_UNATTEND_SECTION, TS_UNATTEND_PERMKEY, &iValue))
  184. {
  185. if (iValue == PERM_TS4)
  186. {
  187. *pPermMode = PERM_TS4;
  188. }
  189. else if (iValue == PERM_WIN2K)
  190. {
  191. *pPermMode = PERM_WIN2K;
  192. }
  193. else
  194. {
  195. LOGMESSAGE2(_T("ERROR, Invalid value for %s (%d) in answer file, ignoring..."), TS_UNATTEND_PERMKEY, iValue);
  196. return FALSE;
  197. }
  198. return TRUE;
  199. }
  200. return FALSE;
  201. }
  202. DWORD SetTSVersion (LPCTSTR pszVersion)
  203. {
  204. CRegistry pReg;
  205. DWORD dwRet;
  206. dwRet = pReg.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY);
  207. if (dwRet == ERROR_SUCCESS)
  208. {
  209. dwRet = pReg.WriteRegString(REG_PRODUCT_VER_KEY, pszVersion);
  210. }
  211. return(dwRet);
  212. }
  213. BOOL WasTSInstalled (VOID)
  214. {
  215. return (StateObject.GetInstalltype() != eFreshInstallTS);
  216. }
  217. PSETUP_INIT_COMPONENT GetSetupData ()
  218. {
  219. ASSERT(StateObject.GetSetupData());
  220. return(StateObject.GetSetupData());
  221. }
  222. ETSInstallType TSState::GetInstalltype () const
  223. {
  224. return m_eInstallType;
  225. }
  226. ETSMode TSState::OriginalTSMode () const
  227. {
  228. return m_eOriginalTSMode;
  229. }
  230. ETSMode TSState::CurrentTSMode () const
  231. {
  232. return m_eCurrentTSMode;
  233. }
  234. ETSLicensingMode TSState::NewLicMode () const
  235. {
  236. return m_eNewLicMode;
  237. }
  238. EPermMode TSState::OriginalPermMode () const
  239. {
  240. return m_eOriginalPermMode;
  241. }
  242. EPermMode TSState::CurrentPermMode () const
  243. {
  244. return m_eCurrentPermMode;
  245. }
  246. BOOL TSState::IsFreshInstall () const
  247. {
  248. return !IsStandAlone() && !IsUpgrade();
  249. }
  250. BOOL TSState::IsTSFreshInstall () const
  251. {
  252. return m_eInstallType == eFreshInstallTS;
  253. }
  254. BOOL TSState::IsUpgradeFrom40TS () const
  255. {
  256. return m_eInstallType == eUpgradeFrom40TS;
  257. }
  258. BOOL TSState::IsUpgradeFrom50TS () const
  259. {
  260. return m_eInstallType == eUpgradeFrom50TS;
  261. }
  262. BOOL TSState::IsUpgradeFrom51TS () const
  263. {
  264. return m_eInstallType == eUpgradeFrom51TS;
  265. }
  266. BOOL TSState::IsUpgradeFrom52TS () const
  267. {
  268. return m_eInstallType == eUpgradeFrom52TS;
  269. }
  270. BOOL TSState::IsUnattended () const
  271. {
  272. return (GetSetupData()->SetupData.OperationFlags & SETUPOP_BATCH) ? TRUE : FALSE;
  273. }
  274. BOOL TSState::IsStandAlone () const
  275. {
  276. return (GetSetupData()->SetupData.OperationFlags & SETUPOP_STANDALONE) ? TRUE : FALSE;
  277. }
  278. BOOL TSState::IsGuiModeSetup () const
  279. {
  280. return !IsStandAlone();
  281. }
  282. BOOL TSState::IsWorkstation () const
  283. {
  284. return m_osVersion.wProductType == VER_NT_WORKSTATION;
  285. }
  286. BOOL TSState::IsPersonal () const
  287. {
  288. return m_osVersion.wSuiteMask & VER_SUITE_PERSONAL;
  289. }
  290. BOOL TSState::IsProfessional() const
  291. {
  292. return IsWorkstation() && !IsPersonal();
  293. }
  294. BOOL TSState::IsServer () const
  295. {
  296. return !IsWorkstation();
  297. }
  298. BOOL TSState::IsAdvServerOrHigher () const
  299. {
  300. return IsServer() && ((m_osVersion.wSuiteMask & VER_SUITE_ENTERPRISE) || (m_osVersion.wSuiteMask & VER_SUITE_DATACENTER));
  301. }
  302. BOOL TSState::IsSBS () const
  303. {
  304. return IsServer () && (m_osVersion.wSuiteMask & VER_SUITE_SMALLBUSINESS);
  305. }
  306. BOOL TSState::IsBlade () const
  307. {
  308. if (m_osVersion.wSuiteMask & VER_SUITE_BLADE)
  309. {
  310. ASSERT(IsServer());
  311. return TRUE;
  312. }
  313. return FALSE;
  314. }
  315. BOOL TSState::CanInstallAppServer () const
  316. {
  317. // we dont want to allow app server on blade.
  318. return (IsServer () && !IsBlade() && !IsSBS());
  319. }
  320. BOOL TSState::WasTSInstalled () const
  321. {
  322. return !IsTSFreshInstall();
  323. }
  324. BOOL TSState::WasTSEnabled () const
  325. {
  326. return this->WasTSInstalled() && m_eOriginalTSMode != eTSDisabled;
  327. }
  328. BOOL TSState::IsUpgrade () const
  329. {
  330. return (GetSetupData()->SetupData.OperationFlags & (SETUPOP_NTUPGRADE |
  331. SETUPOP_WIN95UPGRADE |
  332. SETUPOP_WIN31UPGRADE)) ? TRUE : FALSE;
  333. }
  334. BOOL TSState::WasItAppServer () const
  335. {
  336. return eAppServer == OriginalTSMode();
  337. }
  338. BOOL TSState::WasItRemoteAdmin () const
  339. {
  340. return eRemoteAdmin == OriginalTSMode();
  341. }
  342. BOOL TSState::IsItAppServer () const
  343. {
  344. //
  345. // if its app server, we must have app server selected.
  346. //
  347. ASSERT((eAppServer != CurrentTSMode()) || IsAppServerSelected());
  348. //
  349. // if you cannot select app server,it cannot be app server.
  350. //
  351. ASSERT((eAppServer != CurrentTSMode()) || CanInstallAppServer());
  352. return eAppServer == CurrentTSMode();
  353. }
  354. //
  355. // this returns the app server selection state.
  356. //
  357. BOOL TSState::IsAppServerSelected () const
  358. {
  359. return(
  360. GetHelperRoutines().QuerySelectionState(
  361. GetHelperRoutines().OcManagerContext,
  362. APPSRV_COMPONENT_NAME,
  363. OCSELSTATETYPE_CURRENT
  364. )
  365. );
  366. }
  367. BOOL TSState::IsItRemoteAdmin () const
  368. {
  369. // if its RA we must not have app server selected.
  370. ASSERT((eRemoteAdmin != CurrentTSMode()) || !IsAppServerSelected());
  371. return eRemoteAdmin == CurrentTSMode();
  372. }
  373. BOOL TSState::IsAppSrvModeSwitch () const
  374. {
  375. ASSERT(m_bNewStateValid); // you can ask if this is mode switch only in after completeinstall
  376. return WasItAppServer() != IsItAppServer();
  377. // this functions return true if
  378. // 1) its mode switch ( either in standlaone or upgrade )
  379. // 2) if its fresh install of app server
  380. }
  381. BOOL TSState::IsStandAloneModeSwitch () const
  382. {
  383. ASSERT(m_bNewStateValid); // you can ask if this is mode switch only in after completeinstall
  384. if (!IsServer())
  385. return FALSE;
  386. if (!IsStandAlone())
  387. return FALSE;
  388. return WasItAppServer() != IsItAppServer();
  389. }
  390. BOOL TSState::IsTSModeChanging () const
  391. {
  392. return CurrentTSMode() != OriginalTSMode();
  393. }
  394. BOOL TSState::HasChanged () const
  395. {
  396. return ((CurrentTSMode() != OriginalTSMode()) ||
  397. (CurrentPermMode() != OriginalPermMode()));
  398. }
  399. BOOL TSState::IsTSEnableSelected () const
  400. {
  401. //
  402. // For whistler we dont disable TS ever. OS is always TS Enabled.
  403. // But for some reason if we want to privide TS Off facility. This function
  404. // Should return accordingly.
  405. //
  406. return TRUE;
  407. }
  408. void TSState::SetCurrentConnAllowed (BOOL bAllowed)
  409. {
  410. // we must not allow connections for personal.
  411. ASSERT(!bAllowed || !IsPersonal());
  412. m_bCurrentConnAllowed = bAllowed;
  413. }
  414. BOOL TSState::GetCurrentConnAllowed () const
  415. {
  416. return m_bCurrentConnAllowed;
  417. }
  418. BOOL TSState::GetOrigConnAllowed () const
  419. {
  420. return m_bOrigConnAllowed;
  421. }
  422. TSState::TSState ()
  423. {
  424. m_gpInitComponentData = NULL;
  425. m_bNewStateValid = FALSE;
  426. }
  427. TSState::~TSState ()
  428. {
  429. if (m_gpInitComponentData)
  430. LocalFree (m_gpInitComponentData);
  431. }
  432. const PSETUP_INIT_COMPONENT TSState::GetSetupData () const
  433. {
  434. ASSERT(m_gpInitComponentData);
  435. return m_gpInitComponentData;
  436. }
  437. BOOL TSState::SetSetupData (PSETUP_INIT_COMPONENT pSetupData)
  438. {
  439. m_gpInitComponentData = (PSETUP_INIT_COMPONENT)LocalAlloc(LPTR, sizeof(SETUP_INIT_COMPONENT));
  440. if (m_gpInitComponentData == NULL)
  441. {
  442. return(FALSE);
  443. }
  444. CopyMemory(m_gpInitComponentData, pSetupData, sizeof(SETUP_INIT_COMPONENT));
  445. return(TRUE);
  446. }
  447. BOOL TSState::GetNTType ()
  448. {
  449. ZeroMemory(&m_osVersion, sizeof(OSVERSIONINFOEX));
  450. m_osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  451. if (GetVersionEx((LPOSVERSIONINFO )&m_osVersion))
  452. {
  453. return TRUE;
  454. }
  455. else
  456. {
  457. LOGMESSAGE1(_T("GetVersionEx failed, Error = %d"), GetLastError());
  458. return FALSE;
  459. }
  460. }
  461. BOOL TSState::Initialize (PSETUP_INIT_COMPONENT pSetupData)
  462. {
  463. ASSERT(pSetupData);
  464. if ( !SetSetupData(pSetupData))
  465. {
  466. return FALSE;
  467. }
  468. //
  469. // This is a necessary step.
  470. //
  471. if (GetComponentInfHandle())
  472. SetupOpenAppendInfFile(NULL, GetComponentInfHandle(), NULL);
  473. //
  474. // now populate our state variables.
  475. // first check if its a professional or server installation.
  476. //
  477. VERIFY( GetNTType() );
  478. m_eInstallType = ReadInstallType();
  479. // Set Original TS Mode.
  480. switch (m_eInstallType)
  481. {
  482. case eFreshInstallTS:
  483. m_eOriginalTSMode = eTSDisabled;
  484. break;
  485. case eUpgradeFrom40TS:
  486. m_eOriginalTSMode = eAppServer;
  487. break;
  488. case eUpgradeFrom50TS:
  489. case eUpgradeFrom51TS:
  490. case eUpgradeFrom52TS:
  491. case eStandAloneSetup:
  492. m_eOriginalTSMode = ReadTSMode ();
  493. break;
  494. default:
  495. ASSERT(FALSE);
  496. m_eOriginalTSMode = eTSDisabled;
  497. }
  498. // Set Original Permission Modes.
  499. if (m_eOriginalTSMode == eAppServer)
  500. {
  501. m_eOriginalPermMode = ReadPermMode();
  502. }
  503. else
  504. {
  505. m_eOriginalPermMode = PERM_WIN2K;
  506. }
  507. //
  508. // Set Original Connection Allowed Status.
  509. //
  510. if (m_eInstallType == eFreshInstallTS)
  511. {
  512. m_bOrigConnAllowed = FALSE;
  513. }
  514. else
  515. {
  516. m_bOrigConnAllowed = AreConnectionsAllowed();
  517. }
  518. //
  519. // now lets pick default values for the new installation.
  520. //
  521. if (m_eInstallType == eFreshInstallTS)
  522. {
  523. if (IsWorkstation())
  524. {
  525. SetCurrentTSMode (ePersonalTS);
  526. }
  527. else
  528. {
  529. SetCurrentTSMode (eRemoteAdmin);
  530. }
  531. SetCurrentConnAllowed (FALSE);
  532. }
  533. else
  534. {
  535. if (m_eOriginalTSMode == eTSDisabled)
  536. {
  537. //
  538. // for whistler we have TS always on.
  539. // so if ts was disabled perviously, set it to on after upgrade.
  540. // just disallow connections for such upgrades.
  541. //
  542. SetCurrentPermMode (PERM_WIN2K);
  543. SetCurrentTSMode (IsWorkstation() ? ePersonalTS : eRemoteAdmin);
  544. SetCurrentConnAllowed (FALSE);
  545. }
  546. else if (m_eOriginalTSMode == eAppServer && !CanInstallAppServer())
  547. {
  548. //
  549. // this is upgrade from an app server machine to whistler sku that does not support app server.
  550. // we must downgrade this since app server is NOT supported on this sku
  551. //
  552. ASSERT(FALSE); // this upgrade is not a valid case.
  553. SetCurrentPermMode (PERM_WIN2K);
  554. SetCurrentTSMode (eRemoteAdmin);
  555. SetCurrentConnAllowed (m_bOrigConnAllowed);
  556. LOGMESSAGE0(_T("WARNING:Your Terminal Server is uninstalled since its not supported in Server product. Terminal Server is supported only on Advanced Server or Datacenter products"));
  557. // LogErrorToSetupLog(OcErrLevWarning, IDS_STRING_TERMINAL_SERVER_UNINSTALLED);
  558. }
  559. else
  560. {
  561. //
  562. // for all other upgrade cases, retain the original values.
  563. //
  564. SetCurrentTSMode (m_eOriginalTSMode);
  565. SetCurrentPermMode (m_eOriginalPermMode);
  566. if (!IsPersonal())
  567. {
  568. SetCurrentConnAllowed (m_bOrigConnAllowed);
  569. }
  570. else
  571. {
  572. SetCurrentConnAllowed (FALSE);
  573. }
  574. // TurnOffConnectionsForWhistlerServerBetaUpgrades();
  575. }
  576. }
  577. //
  578. // Lets see if we are given the unattended file, to overwrite our new state
  579. //
  580. if (StateObject.IsUnattended())
  581. {
  582. ASSERT(eTSDisabled != CurrentTSMode());
  583. BOOL bAppServerMode;
  584. if (GetAppModeFromAnswerFile(&bAppServerMode))
  585. {
  586. LOGMESSAGE1(_T("Mode Setting is %s in answer file"), bAppServerMode ? _T("AppServer") : _T("RemoteAdmin"));
  587. if (!CanInstallAppServer())
  588. {
  589. // we support TS mode selection only on the adv server or data center.
  590. LOGMESSAGE0(_T("WARNING:Your unattended terminal server mode setting, can not be respected on this installation."));
  591. if (IsWorkstation())
  592. {
  593. SetCurrentTSMode (ePersonalTS);
  594. }
  595. else
  596. {
  597. ASSERT(IsServer());
  598. SetCurrentTSMode (eRemoteAdmin);
  599. }
  600. }
  601. else
  602. {
  603. if (bAppServerMode)
  604. {
  605. SetCurrentTSMode (eAppServer);
  606. SetCurrentConnAllowed(TRUE);
  607. }
  608. else
  609. {
  610. SetCurrentTSMode (eRemoteAdmin);
  611. SetCurrentConnAllowed(FALSE);
  612. }
  613. }
  614. }
  615. EPermMode ePermMode;
  616. if (GetPermissionsSettingsFromUnAttendedFile(&ePermMode))
  617. {
  618. if (ePermMode == PERM_TS4)
  619. {
  620. if (m_eCurrentTSMode != eAppServer)
  621. {
  622. LOGMESSAGE0(_T("WARNING:Your unattended setting:TS4 perm mode is inconsistent, can't be respected on professional or remote admin mode."));
  623. }
  624. else
  625. {
  626. SetCurrentPermMode (PERM_TS4);
  627. }
  628. }
  629. else
  630. {
  631. SetCurrentPermMode (PERM_WIN2K);
  632. }
  633. }
  634. // Read Connection Allowed Settings.
  635. BOOL bAllowConnections;
  636. if (!IsPersonal() && GetAllowConnectionFromAnswerFile (&bAllowConnections))
  637. {
  638. SetCurrentConnAllowed (bAllowConnections);
  639. }
  640. // Read licensing mode
  641. ETSLicensingMode eLicMode;
  642. if (eLicUnset != (eLicMode = GetLicensingModeFromAnswerFile()))
  643. {
  644. if (!CanInstallAppServer() || ((eLicMode != eLicPerDevice) && (eLicMode != eLicPerUser)))
  645. {
  646. LOGMESSAGE0(_T("WARNING:Your unattended setting:licensing mode is inconsistent, can't be respected."));
  647. eLicMode = eLicUnset;
  648. }
  649. else
  650. {
  651. LOGMESSAGE1(_T("Licensing Mode Setting is %s in answer file"), (eLicMode == eLicPerDevice) ? _T("PerDevice") : _T("PerUser"));
  652. }
  653. }
  654. SetNewLicMode(eLicMode);
  655. } // StateObject.IsUnattended()
  656. LogState();
  657. ASSERT( this->Assert () );
  658. return TRUE;
  659. }
  660. void TSState::UpdateState ()
  661. {
  662. m_bNewStateValid = TRUE;
  663. if (IsAppServerSelected())
  664. {
  665. SetCurrentTSMode(eAppServer);
  666. }
  667. else
  668. {
  669. if (IsWorkstation())
  670. {
  671. SetCurrentTSMode(ePersonalTS);
  672. }
  673. else
  674. {
  675. SetCurrentTSMode(eRemoteAdmin);
  676. }
  677. }
  678. ASSERT(StateObject.Assert());
  679. UpdateConnectionAllowed();
  680. }
  681. //
  682. // this really belongs in subtoggle, however we are doing it here, because the
  683. // WriteDenyConnectionRegistry happens in subcore. we must set the correct connection
  684. // value before we write that registry.
  685. //
  686. void TSState::UpdateConnectionAllowed ()
  687. {
  688. //
  689. // whenever TS mode is switched,
  690. // we enable/disable connections allowed.
  691. // however for unattended setup dont need to do this,
  692. // as unattended seutp could have explicitely disabled
  693. // connections.
  694. //
  695. if (!IsUnattended())
  696. {
  697. if (IsStandAloneModeSwitch())
  698. {
  699. if (IsAppServerSelected())
  700. {
  701. SetCurrentConnAllowed(TRUE);
  702. }
  703. else
  704. {
  705. SetCurrentConnAllowed(FALSE);
  706. }
  707. }
  708. }
  709. }
  710. void TSState::SetCurrentTSMode (ETSMode eNewMode)
  711. {
  712. //
  713. // we no more have ts disabled mode.
  714. //
  715. ASSERT(eNewMode != eTSDisabled);
  716. //
  717. // On server machine you cannot have Personal TS.
  718. //
  719. ASSERT(IsServer() || eNewMode == ePersonalTS);
  720. // you can have app server only on advance server or higher.
  721. ASSERT(CanInstallAppServer() || eNewMode != eAppServer);
  722. m_eCurrentTSMode = eNewMode;
  723. if (eNewMode != eAppServer)
  724. {
  725. SetCurrentPermMode (PERM_WIN2K);
  726. }
  727. }
  728. void TSState::SetNewLicMode (ETSLicensingMode eNewMode)
  729. {
  730. //
  731. // we no more have IC mode.
  732. //
  733. ASSERT(eNewMode != eLicInternetConnector);
  734. m_eNewLicMode = eNewMode;
  735. }
  736. void TSState::SetCurrentPermMode (EPermMode eNewMode)
  737. {
  738. //
  739. // if you want to set perm mode to PERM_TS4, you must first set AppServer Mode.
  740. //
  741. // ASSERT(eNewMode != PERM_TS4 || CurrentTSMode() == eAppServer);
  742. m_eCurrentPermMode = eNewMode;
  743. }
  744. ETSInstallType TSState::ReadInstallType () const
  745. {
  746. DWORD dwError;
  747. CRegistry oRegTermsrv;
  748. if ( IsUpgrade() )
  749. {
  750. dwError = oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY);
  751. if (ERROR_SUCCESS == dwError)
  752. {
  753. //
  754. // TS was installed originally
  755. //
  756. DWORD cbVersion = 0;
  757. LPTSTR szVersion = NULL;
  758. //
  759. // Determine if this is a TS 4.0 upgrade.
  760. //
  761. dwError = oRegTermsrv.ReadRegString(REG_PRODUCT_VER_KEY, &szVersion, &cbVersion);
  762. if (ERROR_SUCCESS == dwError)
  763. {
  764. if ((_tcsicmp(szVersion, _T("5.2")) == 0))
  765. {
  766. return eUpgradeFrom52TS;
  767. }
  768. else if ((_tcsicmp(szVersion, _T("5.1")) == 0))
  769. {
  770. return eUpgradeFrom51TS;
  771. }
  772. else if ((_tcsicmp(szVersion, _T("5.0")) == 0))
  773. {
  774. return eUpgradeFrom50TS;
  775. }
  776. else if ((_tcsicmp(szVersion, _T("4.0")) == 0) || (_tcsicmp(szVersion, _T("2.10")) == 0))
  777. {
  778. return eUpgradeFrom40TS;
  779. }
  780. else
  781. {
  782. LOGMESSAGE1(_T("Error, dont recognize previous TS version (%s)"), szVersion);
  783. return eFreshInstallTS;
  784. }
  785. }
  786. else
  787. {
  788. LOGMESSAGE1(_T("Error, Failed to retrive previous TS version, Errorcode = %d"), dwError);
  789. return eFreshInstallTS;
  790. }
  791. }
  792. else
  793. {
  794. LOGMESSAGE1(_T("Could not Open TermSrv Registry, Must be Fresh TS install. Errorcode = %d"), dwError);
  795. return eFreshInstallTS;
  796. }
  797. }
  798. else
  799. {
  800. if (IsStandAlone())
  801. {
  802. return eStandAloneSetup;
  803. }
  804. else
  805. {
  806. //
  807. // this is fresh install.
  808. //
  809. return eFreshInstallTS;
  810. }
  811. }
  812. }
  813. ETSMode TSState::ReadTSMode () const
  814. {
  815. DWORD dwError;
  816. CRegistry oRegTermsrv;
  817. dwError = oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY);
  818. if (ERROR_SUCCESS == dwError)
  819. {
  820. DWORD dwValue = 0;
  821. dwError = oRegTermsrv.ReadRegDWord(TS_ENABLED_VALUE, &dwValue);
  822. if (ERROR_SUCCESS == dwError)
  823. {
  824. if (dwValue == 1)
  825. {
  826. //
  827. // ts was enabled, now find out the mode.
  828. //
  829. if (oRegTermsrv.ReadRegDWord(TS_APPCMP_VALUE, &dwValue) == ERROR_SUCCESS)
  830. {
  831. if (dwValue == 1)
  832. {
  833. ASSERT(IsServer());
  834. return eAppServer;
  835. }
  836. else
  837. {
  838. if (IsWorkstation())
  839. {
  840. return ePersonalTS;
  841. }
  842. else
  843. {
  844. return eRemoteAdmin;
  845. }
  846. }
  847. }
  848. else
  849. {
  850. LOGMESSAGE0(_T("Error, TSMode registry is missing...Is it Beta version of W2k ?"));
  851. return eAppServer;
  852. }
  853. }
  854. else
  855. {
  856. return eTSDisabled;
  857. }
  858. }
  859. else
  860. {
  861. LOGMESSAGE0(_T("Error, Failed to retrive previous TS enabled state, Is it TS40 Box??."));
  862. return eTSDisabled;
  863. }
  864. }
  865. else
  866. {
  867. LOGMESSAGE1(_T("Error Opening TermSrv Registry, ErrorCode = %d"), dwError);
  868. return eTSDisabled;
  869. }
  870. }
  871. BOOL TSState::AreConnectionsAllowed () const
  872. {
  873. DWORD dwError;
  874. CRegistry oRegTermsrv;
  875. dwError = oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY);
  876. if (ERROR_SUCCESS == dwError)
  877. {
  878. DWORD dwDenyConnect;
  879. dwError = oRegTermsrv.ReadRegDWord(DENY_CONN_VALUE, &dwDenyConnect);
  880. if (ERROR_SUCCESS == dwError)
  881. {
  882. return !dwDenyConnect;
  883. }
  884. }
  885. //
  886. // could not read registry, this means connections were allowed.
  887. //
  888. return TRUE;
  889. }
  890. EPermMode TSState::ReadPermMode () const
  891. {
  892. DWORD dwError;
  893. CRegistry oRegTermsrv;
  894. dwError = oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY);
  895. if (ERROR_SUCCESS == dwError)
  896. {
  897. DWORD dwPerm;
  898. dwError = oRegTermsrv.ReadRegDWord(_T("TSUserEnabled"), &dwPerm);
  899. if (ERROR_SUCCESS == dwError)
  900. {
  901. switch(dwPerm)
  902. {
  903. case PERM_TS4:
  904. case PERM_WIN2K:
  905. return (EPermMode)dwPerm;
  906. break;
  907. default:
  908. // The TSUserEnabled key exists with unrecognized value.
  909. // So it's not an upgrade from TS40. Hence return PERM_WIN2K.
  910. LOGMESSAGE1(_T("ERROR:Unrecognized, Permission value %d"), dwPerm);
  911. return PERM_WIN2K;
  912. break;
  913. }
  914. }
  915. else
  916. {
  917. // The Read of TSUserEnabled failed. This key did not exist for TS40.
  918. // So this could very well be upgrade from TS40.
  919. // Check what upgrade it is and return PERM value accordingly.
  920. LOGMESSAGE1(_T("Warning Failed to read Permissions registry, Is it 40 TS / Beta 2000 upgrade > "), dwError);
  921. if (StateObject.IsUpgradeFrom40TS())
  922. return PERM_TS4;
  923. else
  924. return PERM_WIN2K;
  925. }
  926. }
  927. else
  928. {
  929. LOGMESSAGE1(_T("Error Opening TermSrv Registry, Errorcode = %d"), dwError);
  930. return PERM_WIN2K;
  931. }
  932. }
  933. BOOL TSState::LogState () const
  934. {
  935. static BOOL sbLoggedOnce = FALSE;
  936. if (!sbLoggedOnce)
  937. {
  938. LOGMESSAGE0(_T("Setup Parameters ****************************"));
  939. ETSInstallType eInstall = StateObject.GetInstalltype();
  940. switch (eInstall)
  941. {
  942. case eFreshInstallTS:
  943. LOGMESSAGE1(_T("TS InstallType %s"), _T("eFreshInstallTS"));
  944. break;
  945. case eUpgradeFrom40TS:
  946. LOGMESSAGE1(_T("TS InstallType %s"), _T("eUpgradeFrom40TS (TS4 upgrade)"));
  947. break;
  948. case eUpgradeFrom50TS:
  949. LOGMESSAGE1(_T("TS InstallType %s"), _T("eUpgradeFrom50TS (win2k upgrade)"));
  950. break;
  951. case eUpgradeFrom51TS:
  952. LOGMESSAGE1(_T("TS InstallType %s"), _T("eUpgradeFrom51TS (xp upgrade)"));
  953. break;
  954. case eUpgradeFrom52TS:
  955. LOGMESSAGE1(_T("TS InstallType %s"), _T("eUpgradeFrom52TS (Windows Server 2003 upgrade)"));
  956. break;
  957. case eStandAloneSetup:
  958. LOGMESSAGE1(_T("TS InstallType %s"), _T("eStandAloneSetup (standalone)"));
  959. break;
  960. default:
  961. LOGMESSAGE1(_T("TS InstallType %s"), _T("ERROR:UNKNOWN"));
  962. ASSERT(FALSE);
  963. }
  964. LOGMESSAGE0(_T("-------------------------------------------------------------------"));
  965. LOGMESSAGE1(_T("We are running on = %s"), StateObject.IsWorkstation() ? _T("Wks") : _T("Srv"));
  966. LOGMESSAGE1(_T("Is this adv server = %s"), StateObject.IsAdvServerOrHigher()? _T("Yes") : _T("No"));
  967. LOGMESSAGE1(_T("Is this Home Edition = %s"), StateObject.IsPersonal()? _T("Yes") : _T("No"));
  968. LOGMESSAGE1(_T("Is this SBS server = %s"), StateObject.IsSBS() ? _T("Yes") : _T("No"));
  969. LOGMESSAGE1(_T("Is this Blade = %s"), StateObject.IsBlade() ? _T("Yes") : _T("No"));
  970. LOGMESSAGE1(_T("IsStandAloneSetup = %s"), StateObject.IsStandAlone() ? _T("Yes") : _T("No"));
  971. LOGMESSAGE1(_T("IsFreshInstall = %s"), StateObject.IsFreshInstall() ? _T("Yes") : _T("No"));
  972. LOGMESSAGE1(_T("IsUnattended = %s"), StateObject.IsUnattended() ? _T("Yes") : _T("No"));
  973. LOGMESSAGE0(_T("Original State ******************************"));
  974. LOGMESSAGE1(_T("WasTSInstalled = %s"), StateObject.WasTSInstalled() ? _T("Yes") : _T("No"));
  975. LOGMESSAGE1(_T("WasTSEnabled = %s"), StateObject.WasTSEnabled() ? _T("Yes") : _T("No"));
  976. LOGMESSAGE1(_T("OriginalPermMode = %s"), StateObject.OriginalPermMode() == PERM_TS4 ? _T("TS4") : _T("WIN2K"));
  977. ETSMode eOriginalTSMode = StateObject.OriginalTSMode();
  978. switch (eOriginalTSMode)
  979. {
  980. case eRemoteAdmin:
  981. LOGMESSAGE1(_T("Original TS Mode = %s"), _T("Remote Admin"));
  982. break;
  983. case eAppServer:
  984. LOGMESSAGE1(_T("Original TS Mode = %s"), _T("App Server"));
  985. break;
  986. case eTSDisabled:
  987. LOGMESSAGE1(_T("Original TS Mode = %s"), _T("TS Disabled"));
  988. break;
  989. case ePersonalTS:
  990. LOGMESSAGE1(_T("Original TS Mode = %s"), _T("Personal TS"));
  991. break;
  992. default:
  993. LOGMESSAGE1(_T("Original TS Mode = %s"), _T("Unknown"));
  994. }
  995. sbLoggedOnce = TRUE;
  996. }
  997. LOGMESSAGE0(_T("Current State ******************************"));
  998. ETSMode eCurrentMode = StateObject.CurrentTSMode();
  999. switch (eCurrentMode)
  1000. {
  1001. case eRemoteAdmin:
  1002. LOGMESSAGE1(_T("New TS Mode = %s"), _T("Remote Admin"));
  1003. break;
  1004. case eAppServer:
  1005. LOGMESSAGE1(_T("New TS Mode = %s"), _T("App Server"));
  1006. break;
  1007. case eTSDisabled:
  1008. LOGMESSAGE1(_T("New TS Mode = %s"), _T("TS Disabled"));
  1009. break;
  1010. case ePersonalTS:
  1011. LOGMESSAGE1(_T("New TS Mode = %s"), _T("Personal TS"));
  1012. break;
  1013. default:
  1014. LOGMESSAGE1(_T("New TS Mode = %s"), _T("Unknown"));
  1015. }
  1016. EPermMode ePermMode = StateObject.CurrentPermMode();
  1017. switch (ePermMode)
  1018. {
  1019. case PERM_WIN2K:
  1020. LOGMESSAGE1(_T("New Permissions Mode = %s"), _T("PERM_WIN2K"));
  1021. break;
  1022. case PERM_TS4:
  1023. LOGMESSAGE1(_T("New Permissions Mode = %s"), _T("PERM_TS4"));
  1024. break;
  1025. default:
  1026. LOGMESSAGE1(_T("New Permissions Mode = %s"), _T("Unknown"));
  1027. }
  1028. LOGMESSAGE1(_T("New Connections Allowed = %s"), StateObject.GetCurrentConnAllowed() ? _T("True") : _T("False"));
  1029. return TRUE;
  1030. }
  1031. BOOL TSState::IsX86 () const
  1032. {
  1033. SYSTEM_INFO sysInfo;
  1034. ZeroMemory(&sysInfo, sizeof(sysInfo));
  1035. GetSystemInfo(&sysInfo);
  1036. return sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL;
  1037. }
  1038. BOOL TSState::IsAMD64 () const
  1039. {
  1040. SYSTEM_INFO sysInfo;
  1041. ZeroMemory(&sysInfo, sizeof(sysInfo));
  1042. GetSystemInfo(&sysInfo);
  1043. return sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64;
  1044. }
  1045. BOOL TSState::Assert () const
  1046. {
  1047. // its assert !!
  1048. ASSERT(IsCheckedBuild());
  1049. // on professional there is no remote admin
  1050. ASSERT(IsServer() || !WasItRemoteAdmin());
  1051. // on professional there is no app server.
  1052. ASSERT(IsServer() || !WasItAppServer());
  1053. // if original perm was TS4 compatible, it must have been app server.
  1054. ASSERT((OriginalPermMode() != PERM_TS4) || WasItAppServer());
  1055. // make sure standalone is consistant.
  1056. ASSERT(IsStandAlone() == (GetInstalltype() == eStandAloneSetup));
  1057. if (m_bNewStateValid)
  1058. {
  1059. // we no more have disable ts state.
  1060. ASSERT(CurrentTSMode() != eTSDisabled);
  1061. // AppServer mode is available only for adv server, datacenter
  1062. ASSERT(CanInstallAppServer() || !IsItAppServer());
  1063. // we cannot be in RA mode for Professional.
  1064. ASSERT(IsServer() || !IsItRemoteAdmin());
  1065. // if permissions mode is TS4 compatible, it must be appserver
  1066. ASSERT((CurrentPermMode() != PERM_TS4) || IsItAppServer());
  1067. // we should never allwe connections on Personal
  1068. ASSERT(!IsPersonal() || !GetCurrentConnAllowed ());
  1069. }
  1070. return TRUE;
  1071. }
  1072. BOOL TSState::CanShowStartupPopup() const
  1073. {
  1074. if (!StateObject.IsUnattended())
  1075. return TRUE;
  1076. int iValue = 0;
  1077. if (ReadIntFromAnswerFile(TS_UNATTEND_SECTION, TS_DENY_POPUP, &iValue))
  1078. {
  1079. if (iValue != 0)
  1080. return FALSE;
  1081. }
  1082. return TRUE;
  1083. }
  1084. BOOL TSState::IsCheckedBuild () const
  1085. {
  1086. #ifdef DBG
  1087. return TRUE;
  1088. #else
  1089. return FALSE;
  1090. #endif
  1091. }