Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1146 lines
29 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("perseat"), szBuffer))
  144. {
  145. return eLicPerSeat;
  146. }
  147. else if (0 == _tcsicmp(_T("persession"), szBuffer))
  148. {
  149. return eLicPerSession;
  150. }
  151. else if (0 == _tcsicmp(_T("pts"), szBuffer))
  152. {
  153. return eLicPTS;
  154. }
  155. else if (0 == _tcsicmp(_T("remoteadmin"), szBuffer))
  156. {
  157. return eLicRemoteAdmin;
  158. }
  159. else if (0 == _tcsicmp(_T("internetconnector"), szBuffer))
  160. {
  161. return eLicInternetConnector;
  162. }
  163. else
  164. {
  165. LOGMESSAGE2(_T("ERROR, Invalid value for %s (%s) in answer file. Ignoring..."), TS_UNATTEND_SECTION, szBuffer);
  166. return eLicUnset;
  167. }
  168. }
  169. else
  170. {
  171. return eLicUnset;
  172. }
  173. }
  174. BOOL GetPermissionsSettingsFromUnAttendedFile( EPermMode *pPermMode )
  175. {
  176. ASSERT(pPermMode);
  177. int iValue;
  178. if (ReadIntFromAnswerFile(TS_UNATTEND_SECTION, TS_UNATTEND_PERMKEY, &iValue))
  179. {
  180. if (iValue == PERM_TS4)
  181. {
  182. *pPermMode = PERM_TS4;
  183. }
  184. else if (iValue == PERM_WIN2K)
  185. {
  186. *pPermMode = PERM_WIN2K;
  187. }
  188. else
  189. {
  190. LOGMESSAGE2(_T("ERROR, Invalid value for %s (%d) in answer file, ignoring..."), TS_UNATTEND_PERMKEY, iValue);
  191. return FALSE;
  192. }
  193. return TRUE;
  194. }
  195. return FALSE;
  196. }
  197. DWORD SetTSVersion (LPCTSTR pszVersion)
  198. {
  199. CRegistry pReg;
  200. DWORD dwRet;
  201. dwRet = pReg.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY);
  202. if (dwRet == ERROR_SUCCESS)
  203. {
  204. dwRet = pReg.WriteRegString(REG_PRODUCT_VER_KEY, pszVersion);
  205. }
  206. return(dwRet);
  207. }
  208. BOOL WasTSInstalled (VOID)
  209. {
  210. return (StateObject.GetInstalltype() != eFreshInstallTS);
  211. }
  212. PSETUP_INIT_COMPONENT GetSetupData ()
  213. {
  214. ASSERT(StateObject.GetSetupData());
  215. return(StateObject.GetSetupData());
  216. }
  217. ETSInstallType TSState::GetInstalltype () const
  218. {
  219. return m_eInstallType;
  220. }
  221. ETSMode TSState::OriginalTSMode () const
  222. {
  223. return m_eOriginalTSMode;
  224. }
  225. ETSMode TSState::CurrentTSMode () const
  226. {
  227. return m_eCurrentTSMode;
  228. }
  229. ETSLicensingMode TSState::NewLicMode () const
  230. {
  231. return m_eNewLicMode;
  232. }
  233. EPermMode TSState::OriginalPermMode () const
  234. {
  235. return m_eOriginalPermMode;
  236. }
  237. EPermMode TSState::CurrentPermMode () const
  238. {
  239. return m_eCurrentPermMode;
  240. }
  241. BOOL TSState::IsFreshInstall () const
  242. {
  243. return !IsStandAlone() && !IsUpgrade();
  244. }
  245. BOOL TSState::IsTSFreshInstall () const
  246. {
  247. return m_eInstallType == eFreshInstallTS;
  248. }
  249. BOOL TSState::IsUpgradeFrom40TS () const
  250. {
  251. return m_eInstallType == eUpgradeFrom40TS;
  252. }
  253. BOOL TSState::IsUpgradeFrom50TS () const
  254. {
  255. return m_eInstallType == eUpgradeFrom50TS;
  256. }
  257. BOOL TSState::IsUpgradeFrom51TS () const
  258. {
  259. return m_eInstallType == eUpgradeFrom51TS;
  260. }
  261. BOOL TSState::IsUnattended () const
  262. {
  263. return (GetSetupData()->SetupData.OperationFlags & SETUPOP_BATCH) ? TRUE : FALSE;
  264. }
  265. BOOL TSState::IsStandAlone () const
  266. {
  267. return (GetSetupData()->SetupData.OperationFlags & SETUPOP_STANDALONE) ? TRUE : FALSE;
  268. }
  269. BOOL TSState::IsGuiModeSetup () const
  270. {
  271. return !IsStandAlone();
  272. }
  273. BOOL TSState::IsWorkstation () const
  274. {
  275. return m_osVersion.wProductType == VER_NT_WORKSTATION;
  276. }
  277. BOOL TSState::IsPersonal () const
  278. {
  279. return m_osVersion.wSuiteMask & VER_SUITE_PERSONAL;
  280. }
  281. BOOL TSState::IsProfessional() const
  282. {
  283. return IsWorkstation() && !IsPersonal();
  284. }
  285. BOOL TSState::IsServer () const
  286. {
  287. return !IsWorkstation();
  288. }
  289. BOOL TSState::IsAdvServerOrHigher () const
  290. {
  291. return IsServer () && ((m_osVersion.wSuiteMask & VER_SUITE_ENTERPRISE) || (m_osVersion.wSuiteMask & VER_SUITE_DATACENTER));
  292. }
  293. BOOL TSState::IsSBS() const
  294. {
  295. return IsServer () && (m_osVersion.wSuiteMask & VER_SUITE_SMALLBUSINESS);
  296. }
  297. BOOL TSState::CanInstallAppServer () const
  298. {
  299. return IsAdvServerOrHigher () || IsSBS ();
  300. }
  301. BOOL TSState::WasTSInstalled () const
  302. {
  303. return !IsTSFreshInstall();
  304. }
  305. BOOL TSState::WasTSEnabled () const
  306. {
  307. return this->WasTSInstalled() && m_eOriginalTSMode != eTSDisabled;
  308. }
  309. BOOL TSState::IsUpgrade () const
  310. {
  311. return (GetSetupData()->SetupData.OperationFlags & (SETUPOP_NTUPGRADE |
  312. SETUPOP_WIN95UPGRADE |
  313. SETUPOP_WIN31UPGRADE)) ? TRUE : FALSE;
  314. }
  315. BOOL TSState::WasItAppServer () const
  316. {
  317. return eAppServer == OriginalTSMode();
  318. }
  319. BOOL TSState::WasItRemoteAdmin () const
  320. {
  321. return eRemoteAdmin == OriginalTSMode();
  322. }
  323. BOOL TSState::IsItAppServer () const
  324. {
  325. //
  326. // if its app server, we must have app server selected.
  327. //
  328. ASSERT((eAppServer != CurrentTSMode()) || IsAppServerSelected());
  329. //
  330. // if you cannot select app server,it cannot be app server.
  331. //
  332. ASSERT((eAppServer != CurrentTSMode()) || CanInstallAppServer());
  333. return eAppServer == CurrentTSMode();
  334. }
  335. //
  336. // this returns the app server selection state.
  337. //
  338. BOOL TSState::IsAppServerSelected () const
  339. {
  340. return(
  341. GetHelperRoutines().QuerySelectionState(
  342. GetHelperRoutines().OcManagerContext,
  343. APPSRV_COMPONENT_NAME,
  344. OCSELSTATETYPE_CURRENT
  345. )
  346. );
  347. }
  348. BOOL TSState::IsItRemoteAdmin () const
  349. {
  350. // if its RA we must not have app server selected.
  351. ASSERT((eRemoteAdmin != CurrentTSMode()) || !IsAppServerSelected());
  352. return eRemoteAdmin == CurrentTSMode();
  353. }
  354. BOOL TSState::IsAppSrvModeSwitch () const
  355. {
  356. ASSERT(m_bNewStateValid); // you cannot ask if this is mode switch only in after completeinstall
  357. return WasItAppServer() != IsItAppServer();
  358. }
  359. BOOL TSState::IsTSModeChanging () const
  360. {
  361. return CurrentTSMode() != OriginalTSMode();
  362. }
  363. BOOL TSState::HasChanged () const
  364. {
  365. return ((CurrentTSMode() != OriginalTSMode()) ||
  366. (CurrentPermMode() != OriginalPermMode()));
  367. }
  368. BOOL TSState::IsTSEnableSelected () const
  369. {
  370. //
  371. // For whistler we dont disable TS ever. OS is always TS Enabled.
  372. // But for some reason if we want to privide TS Off facility. This function
  373. // Should return accordingly.
  374. //
  375. return TRUE;
  376. }
  377. void TSState::SetCurrentConnAllowed (BOOL bAllowed)
  378. {
  379. // we must not allow connections for personal.
  380. ASSERT(!bAllowed || !IsPersonal());
  381. m_bCurrentConnAllowed = bAllowed;
  382. }
  383. BOOL TSState::GetCurrentConnAllowed () const
  384. {
  385. return m_bCurrentConnAllowed;
  386. }
  387. BOOL TSState::GetOrigConnAllowed () const
  388. {
  389. return m_bOrigConnAllowed;
  390. }
  391. TSState::TSState ()
  392. {
  393. m_gpInitComponentData = NULL;
  394. m_bNewStateValid = FALSE;
  395. }
  396. TSState::~TSState ()
  397. {
  398. if (m_gpInitComponentData)
  399. LocalFree (m_gpInitComponentData);
  400. }
  401. const PSETUP_INIT_COMPONENT TSState::GetSetupData () const
  402. {
  403. ASSERT(m_gpInitComponentData);
  404. return m_gpInitComponentData;
  405. }
  406. BOOL TSState::SetSetupData (PSETUP_INIT_COMPONENT pSetupData)
  407. {
  408. m_gpInitComponentData = (PSETUP_INIT_COMPONENT)LocalAlloc(LPTR, sizeof(SETUP_INIT_COMPONENT));
  409. if (m_gpInitComponentData == NULL)
  410. {
  411. return(FALSE);
  412. }
  413. CopyMemory(m_gpInitComponentData, pSetupData, sizeof(SETUP_INIT_COMPONENT));
  414. return(TRUE);
  415. }
  416. BOOL TSState::GetNTType ()
  417. {
  418. ZeroMemory(&m_osVersion, sizeof(OSVERSIONINFOEX));
  419. m_osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  420. if (GetVersionEx((LPOSVERSIONINFO )&m_osVersion))
  421. {
  422. return TRUE;
  423. }
  424. else
  425. {
  426. LOGMESSAGE1(_T("GetVersionEx failed, Error = %d"), GetLastError());
  427. return FALSE;
  428. }
  429. }
  430. BOOL TSState::Initialize (PSETUP_INIT_COMPONENT pSetupData)
  431. {
  432. ASSERT(pSetupData);
  433. if ( !SetSetupData(pSetupData))
  434. {
  435. return FALSE;
  436. }
  437. //
  438. // This is a necessary step.
  439. //
  440. if (GetComponentInfHandle())
  441. SetupOpenAppendInfFile(NULL, GetComponentInfHandle(), NULL);
  442. //
  443. // now populate our state variables.
  444. // first check if its a professional or server installation.
  445. //
  446. VERIFY( GetNTType() );
  447. m_eInstallType = ReadInstallType();
  448. // Set Original TS Mode.
  449. switch (m_eInstallType)
  450. {
  451. case eFreshInstallTS:
  452. m_eOriginalTSMode = eTSDisabled;
  453. break;
  454. case eUpgradeFrom40TS:
  455. m_eOriginalTSMode = eAppServer;
  456. break;
  457. case eUpgradeFrom50TS:
  458. case eUpgradeFrom51TS:
  459. case eStandAloneSetup:
  460. m_eOriginalTSMode = ReadTSMode ();
  461. break;
  462. default:
  463. ASSERT(FALSE);
  464. m_eOriginalTSMode = eTSDisabled;
  465. }
  466. // Set Original Permission Modes.
  467. if (m_eOriginalTSMode == eAppServer)
  468. {
  469. m_eOriginalPermMode = ReadPermMode();
  470. }
  471. else
  472. {
  473. m_eOriginalPermMode = PERM_WIN2K;
  474. }
  475. //
  476. // Set Original Connection Allowed Status.
  477. //
  478. if (m_eInstallType == eFreshInstallTS)
  479. {
  480. m_bOrigConnAllowed = FALSE;
  481. }
  482. else
  483. {
  484. m_bOrigConnAllowed = AreConnectionsAllowed();
  485. }
  486. //
  487. // now lets pick default values for the new installation.
  488. //
  489. if (m_eInstallType == eFreshInstallTS)
  490. {
  491. if (IsWorkstation())
  492. {
  493. SetCurrentTSMode (ePersonalTS);
  494. SetCurrentConnAllowed (FALSE);
  495. }
  496. else
  497. {
  498. SetCurrentTSMode (eRemoteAdmin);
  499. SetCurrentConnAllowed (TRUE);
  500. }
  501. }
  502. else
  503. {
  504. if (m_eOriginalTSMode == eTSDisabled)
  505. {
  506. //
  507. // for whistler we have TS always on.
  508. // so if ts was disabled perviously, set it to on after upgrade.
  509. // just disallow connections for such upgrades.
  510. //
  511. SetCurrentPermMode (PERM_WIN2K);
  512. SetCurrentTSMode (IsWorkstation() ? ePersonalTS : eRemoteAdmin);
  513. SetCurrentConnAllowed (FALSE);
  514. }
  515. else if (m_eOriginalTSMode == eAppServer && !CanInstallAppServer())
  516. {
  517. //
  518. // this is upgrade from an app server machine to whistler server.
  519. // we must downgrade this. since whistler server does not support app server anymore
  520. // app server is supported on adv server or higher.
  521. //
  522. SetCurrentPermMode (PERM_WIN2K);
  523. SetCurrentTSMode (eRemoteAdmin);
  524. SetCurrentConnAllowed (m_bOrigConnAllowed);
  525. 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"));
  526. // LogErrorToSetupLog(OcErrLevWarning, IDS_STRING_TERMINAL_SERVER_UNINSTALLED);
  527. }
  528. else
  529. {
  530. //
  531. // for all other upgrade cases, retain the original values.
  532. //
  533. SetCurrentTSMode (m_eOriginalTSMode);
  534. SetCurrentPermMode (m_eOriginalPermMode);
  535. if (!IsPersonal())
  536. {
  537. SetCurrentConnAllowed (m_bOrigConnAllowed);
  538. }
  539. else
  540. {
  541. SetCurrentConnAllowed (FALSE);
  542. }
  543. }
  544. }
  545. //
  546. // Lets see if we are given the unattended file, to overwrite our new state
  547. //
  548. if (StateObject.IsUnattended())
  549. {
  550. ASSERT(eTSDisabled != CurrentTSMode());
  551. BOOL bAppServerMode;
  552. if (GetAppModeFromAnswerFile(&bAppServerMode))
  553. {
  554. LOGMESSAGE1(_T("Mode Setting is %s in answer file"), bAppServerMode ? _T("AppServer") : _T("RemoteAdmin"));
  555. if (!CanInstallAppServer())
  556. {
  557. // we support TS mode selection only on the adv server or data center.
  558. LOGMESSAGE0(_T("WARNING:Your unattended terminal server mode setting, can not be respected on this installation."));
  559. if (IsWorkstation())
  560. {
  561. SetCurrentTSMode (ePersonalTS);
  562. }
  563. else
  564. {
  565. ASSERT(IsServer());
  566. SetCurrentTSMode (eRemoteAdmin);
  567. }
  568. }
  569. else
  570. {
  571. if (bAppServerMode)
  572. {
  573. SetCurrentTSMode (eAppServer);
  574. }
  575. else
  576. {
  577. SetCurrentTSMode (eRemoteAdmin);
  578. }
  579. }
  580. }
  581. EPermMode ePermMode;
  582. if (GetPermissionsSettingsFromUnAttendedFile(&ePermMode))
  583. {
  584. if (ePermMode == PERM_TS4)
  585. {
  586. if (m_eCurrentTSMode != eAppServer)
  587. {
  588. LOGMESSAGE0(_T("WARNING:Your unattended setting:TS4 perm mode is inconsistent, can't be respected on professional or remote admin mode."));
  589. }
  590. else
  591. {
  592. SetCurrentPermMode (PERM_TS4);
  593. }
  594. }
  595. else
  596. {
  597. SetCurrentPermMode (PERM_WIN2K);
  598. }
  599. }
  600. // Read Connection Allowed Settings.
  601. BOOL bAllowConnections;
  602. if (!IsPersonal() && GetAllowConnectionFromAnswerFile (&bAllowConnections))
  603. {
  604. SetCurrentConnAllowed (bAllowConnections);
  605. }
  606. // Read licensing mode
  607. ETSLicensingMode eLicMode;
  608. if (eLicUnset != (eLicMode = GetLicensingModeFromAnswerFile()))
  609. {
  610. if (!CanInstallAppServer() || ((eLicMode != eLicPerSeat) && (eLicMode != eLicPerSession)))
  611. {
  612. LOGMESSAGE0(_T("WARNING:Your unattended setting:licensing mode is inconsistent, can't be respected."));
  613. eLicMode = eLicUnset;
  614. }
  615. }
  616. SetNewLicMode(eLicMode);
  617. } // StateObject.IsUnattended()
  618. LogState();
  619. ASSERT( this->Assert () );
  620. return TRUE;
  621. }
  622. void TSState::UpdateState ()
  623. {
  624. m_bNewStateValid = TRUE;
  625. if (IsAppServerSelected())
  626. {
  627. SetCurrentTSMode(eAppServer);
  628. }
  629. else
  630. {
  631. if (IsWorkstation())
  632. {
  633. SetCurrentTSMode(ePersonalTS);
  634. }
  635. else
  636. {
  637. SetCurrentTSMode(eRemoteAdmin);
  638. }
  639. }
  640. ASSERT(StateObject.Assert());
  641. }
  642. void TSState::SetCurrentTSMode (ETSMode eNewMode)
  643. {
  644. //
  645. // we no more have ts disabled mode.
  646. //
  647. ASSERT(eNewMode != eTSDisabled);
  648. //
  649. // On server machine you cannot have Personal TS.
  650. //
  651. ASSERT(IsServer() || eNewMode == ePersonalTS);
  652. // you can have app server only on advance server or higher.
  653. ASSERT(CanInstallAppServer() || eNewMode != eAppServer);
  654. m_eCurrentTSMode = eNewMode;
  655. if (eNewMode != eAppServer)
  656. {
  657. SetCurrentPermMode (PERM_WIN2K);
  658. }
  659. }
  660. void TSState::SetNewLicMode (ETSLicensingMode eNewMode)
  661. {
  662. //
  663. // we no more have IC mode.
  664. //
  665. ASSERT(eNewMode != eLicInternetConnector);
  666. m_eNewLicMode = eNewMode;
  667. }
  668. void TSState::SetCurrentPermMode (EPermMode eNewMode)
  669. {
  670. //
  671. // if you want to set perm mode to PERM_TS4, you must first set AppServer Mode.
  672. //
  673. // ASSERT(eNewMode != PERM_TS4 || CurrentTSMode() == eAppServer);
  674. m_eCurrentPermMode = eNewMode;
  675. }
  676. ETSInstallType TSState::ReadInstallType () const
  677. {
  678. DWORD dwError;
  679. CRegistry oRegTermsrv;
  680. if ( IsUpgrade() )
  681. {
  682. dwError = oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY);
  683. if (ERROR_SUCCESS == dwError)
  684. {
  685. //
  686. // TS was installed originally
  687. //
  688. DWORD cbVersion = 0;
  689. LPTSTR szVersion = NULL;
  690. //
  691. // Determine if this is a TS 4.0 upgrade.
  692. //
  693. dwError = oRegTermsrv.ReadRegString(REG_PRODUCT_VER_KEY, &szVersion, &cbVersion);
  694. if (ERROR_SUCCESS == dwError)
  695. {
  696. if ((_tcsicmp(szVersion, _T("5.1")) == 0))
  697. {
  698. return eUpgradeFrom51TS;
  699. }
  700. else if ((_tcsicmp(szVersion, _T("5.0")) == 0))
  701. {
  702. return eUpgradeFrom50TS;
  703. }
  704. else if ((_tcsicmp(szVersion, _T("4.0")) == 0) || (_tcsicmp(szVersion, _T("2.10")) == 0))
  705. {
  706. return eUpgradeFrom40TS;
  707. }
  708. else
  709. {
  710. LOGMESSAGE1(_T("Error, dont recognize previous TS version (%s)"), szVersion);
  711. return eFreshInstallTS;
  712. }
  713. }
  714. else
  715. {
  716. LOGMESSAGE1(_T("Error, Failed to retrive previous TS version, Errorcode = %d"), dwError);
  717. return eFreshInstallTS;
  718. }
  719. }
  720. else
  721. {
  722. LOGMESSAGE1(_T("Could not Open TermSrv Registry, Must be Fresh TS install. Errorcode = %d"), dwError);
  723. return eFreshInstallTS;
  724. }
  725. }
  726. else
  727. {
  728. if (IsStandAlone())
  729. {
  730. return eStandAloneSetup;
  731. }
  732. else
  733. {
  734. //
  735. // this is fresh install.
  736. //
  737. return eFreshInstallTS;
  738. }
  739. }
  740. }
  741. ETSMode TSState::ReadTSMode () const
  742. {
  743. DWORD dwError;
  744. CRegistry oRegTermsrv;
  745. dwError = oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY);
  746. if (ERROR_SUCCESS == dwError)
  747. {
  748. DWORD dwValue = 0;
  749. dwError = oRegTermsrv.ReadRegDWord(TS_ENABLED_VALUE, &dwValue);
  750. if (ERROR_SUCCESS == dwError)
  751. {
  752. if (dwValue == 1)
  753. {
  754. //
  755. // ts was enabled, now find out the mode.
  756. //
  757. if (oRegTermsrv.ReadRegDWord(TS_APPCMP_VALUE, &dwValue) == ERROR_SUCCESS)
  758. {
  759. if (dwValue == 1)
  760. {
  761. ASSERT(IsServer());
  762. return eAppServer;
  763. }
  764. else
  765. {
  766. if (IsWorkstation())
  767. {
  768. return ePersonalTS;
  769. }
  770. else
  771. {
  772. return eRemoteAdmin;
  773. }
  774. }
  775. }
  776. else
  777. {
  778. LOGMESSAGE0(_T("Error, TSMode registry is missing...Is it Beta version of W2k ?"));
  779. return eAppServer;
  780. }
  781. }
  782. else
  783. {
  784. return eTSDisabled;
  785. }
  786. }
  787. else
  788. {
  789. LOGMESSAGE0(_T("Error, Failed to retrive previous TS enabled state, Is it TS40 Box??."));
  790. return eTSDisabled;
  791. }
  792. }
  793. else
  794. {
  795. LOGMESSAGE1(_T("Error Opening TermSrv Registry, ErrorCode = %d"), dwError);
  796. return eTSDisabled;
  797. }
  798. }
  799. BOOL TSState::AreConnectionsAllowed () const
  800. {
  801. DWORD dwError;
  802. CRegistry oRegTermsrv;
  803. dwError = oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY);
  804. if (ERROR_SUCCESS == dwError)
  805. {
  806. DWORD dwDenyConnect;
  807. dwError = oRegTermsrv.ReadRegDWord(DENY_CONN_VALUE, &dwDenyConnect);
  808. if (ERROR_SUCCESS == dwError)
  809. {
  810. return !dwDenyConnect;
  811. }
  812. }
  813. //
  814. // could not read registry, this means connections were allowed.
  815. //
  816. return TRUE;
  817. }
  818. EPermMode TSState::ReadPermMode () const
  819. {
  820. DWORD dwError;
  821. CRegistry oRegTermsrv;
  822. dwError = oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, REG_CONTROL_TS_KEY);
  823. if (ERROR_SUCCESS == dwError)
  824. {
  825. DWORD dwPerm;
  826. dwError = oRegTermsrv.ReadRegDWord(_T("TSUserEnabled"), &dwPerm);
  827. if (ERROR_SUCCESS == dwError)
  828. {
  829. switch(dwPerm)
  830. {
  831. case PERM_TS4:
  832. case PERM_WIN2K:
  833. return (EPermMode)dwPerm;
  834. break;
  835. default:
  836. LOGMESSAGE1(_T("ERROR:Unrecognized, Permission value %d"), dwPerm);
  837. return PERM_TS4;
  838. break;
  839. }
  840. }
  841. else
  842. {
  843. LOGMESSAGE1(_T("Warning Failed to read Permissions registry, Is it 40 TS / Beta 2000 upgrade > "), dwError);
  844. return PERM_TS4;
  845. }
  846. }
  847. else
  848. {
  849. LOGMESSAGE1(_T("Error Opening TermSrv Registry, Errorcode = %d"), dwError);
  850. return PERM_WIN2K;
  851. }
  852. }
  853. BOOL TSState::LogState () const
  854. {
  855. static BOOL sbLoggedOnce = FALSE;
  856. if (!sbLoggedOnce)
  857. {
  858. LOGMESSAGE0(_T("Setup Parameters ****************************"));
  859. LOGMESSAGE1(_T("We are running on %s"), StateObject.IsWorkstation() ? _T("Wks") : _T("Srv"));
  860. LOGMESSAGE1(_T("Is this adv server %s"), StateObject.IsAdvServerOrHigher()? _T("Yes") : _T("No"));
  861. LOGMESSAGE1(_T("Is this Personal (Home Edition) %s"), StateObject.IsPersonal()? _T("Yes") : _T("No"));
  862. LOGMESSAGE1(_T("Is this SBS server %s"), StateObject.IsSBS() ? _T("Yes") : _T("No"));
  863. LOGMESSAGE1(_T("IsStandAloneSetup = %s"), StateObject.IsStandAlone() ? _T("Yes") : _T("No"));
  864. LOGMESSAGE1(_T("IsFreshInstall = %s"), StateObject.IsFreshInstall() ? _T("Yes") : _T("No"));
  865. LOGMESSAGE1(_T("IsTSFreshInstall = %s"), StateObject.IsTSFreshInstall() ? _T("Yes") : _T("No"));
  866. LOGMESSAGE1(_T("IsUnattendSetup = %s"), StateObject.IsUnattended() ? _T("Yes") : _T("No"));
  867. LOGMESSAGE1(_T("IsUpgradeFromTS40 = %s"), StateObject.IsUpgradeFrom40TS() ? _T("Yes") : _T("No"));
  868. LOGMESSAGE1(_T("IsUpgradeFromNT50 = %s"), StateObject.IsUpgradeFrom50TS() ? _T("Yes") : _T("No"));
  869. LOGMESSAGE1(_T("IsUpgradeFromNT51 = %s"), StateObject.IsUpgradeFrom51TS() ? _T("Yes") : _T("No"));
  870. LOGMESSAGE1(_T("IsUnattended = %s"), StateObject.IsUnattended() ? _T("Yes") : _T("No"));
  871. LOGMESSAGE0(_T("Original State ******************************"));
  872. LOGMESSAGE1(_T("WasTSInstalled = %s"), StateObject.WasTSInstalled() ? _T("Yes") : _T("No"));
  873. LOGMESSAGE1(_T("WasTSEnabled = %s"), StateObject.WasTSEnabled() ? _T("Yes") : _T("No"));
  874. LOGMESSAGE1(_T("OriginalPermMode = %s"), StateObject.OriginalPermMode() == PERM_TS4 ? _T("TS4") : _T("WIN2K"));
  875. ETSMode eOriginalTSMode = StateObject.OriginalTSMode();
  876. switch (eOriginalTSMode)
  877. {
  878. case eRemoteAdmin:
  879. LOGMESSAGE1(_T("Original TS Mode = %s"), _T("Remote Admin"));
  880. break;
  881. case eAppServer:
  882. LOGMESSAGE1(_T("Original TS Mode = %s"), _T("App Server"));
  883. break;
  884. case eTSDisabled:
  885. LOGMESSAGE1(_T("Original TS Mode = %s"), _T("TS Disabled"));
  886. break;
  887. case ePersonalTS:
  888. LOGMESSAGE1(_T("Original TS Mode = %s"), _T("Personal TS"));
  889. break;
  890. default:
  891. LOGMESSAGE1(_T("Original TS Mode = %s"), _T("Unknown"));
  892. }
  893. sbLoggedOnce = TRUE;
  894. }
  895. LOGMESSAGE0(_T("Current State ******************************"));
  896. ETSMode eCurrentMode = StateObject.CurrentTSMode();
  897. switch (eCurrentMode)
  898. {
  899. case eRemoteAdmin:
  900. LOGMESSAGE1(_T("New TS Mode = %s"), _T("Remote Admin"));
  901. break;
  902. case eAppServer:
  903. LOGMESSAGE1(_T("New TS Mode = %s"), _T("App Server"));
  904. break;
  905. case eTSDisabled:
  906. LOGMESSAGE1(_T("New TS Mode = %s"), _T("TS Disabled"));
  907. break;
  908. case ePersonalTS:
  909. LOGMESSAGE1(_T("New TS Mode = %s"), _T("Personal TS"));
  910. break;
  911. default:
  912. LOGMESSAGE1(_T("New TS Mode = %s"), _T("Unknown"));
  913. }
  914. EPermMode ePermMode = StateObject.CurrentPermMode();
  915. switch (ePermMode)
  916. {
  917. case PERM_WIN2K:
  918. LOGMESSAGE1(_T("New Permissions Mode = %s"), _T("PERM_WIN2K"));
  919. break;
  920. case PERM_TS4:
  921. LOGMESSAGE1(_T("New Permissions Mode = %s"), _T("PERM_TS4"));
  922. break;
  923. default:
  924. LOGMESSAGE1(_T("New Permissions Mode = %s"), _T("Unknown"));
  925. }
  926. LOGMESSAGE1(_T("New Connections Allowed = %s"), StateObject.GetCurrentConnAllowed() ? _T("True") : _T("False"));
  927. return TRUE;
  928. }
  929. BOOL TSState::IsX86 () const
  930. {
  931. SYSTEM_INFO sysInfo;
  932. ZeroMemory(&sysInfo, sizeof(sysInfo));
  933. GetSystemInfo(&sysInfo);
  934. return sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL;
  935. }
  936. BOOL TSState::Assert () const
  937. {
  938. // its assert !!
  939. ASSERT(IsCheckedBuild());
  940. // on professional there is no remote admin
  941. ASSERT(IsServer() || !WasItRemoteAdmin());
  942. // on professional there is no app server.
  943. ASSERT(IsServer() || !WasItAppServer());
  944. // if original perm was TS4 compatible, it must have been app server.
  945. ASSERT((OriginalPermMode() != PERM_TS4) || WasItAppServer());
  946. // make sure standalone is consistant.
  947. ASSERT(IsStandAlone() == (GetInstalltype() == eStandAloneSetup));
  948. if (m_bNewStateValid)
  949. {
  950. // we no more have disable ts state.
  951. ASSERT(CurrentTSMode() != eTSDisabled);
  952. // AppServer mode is available only for adv server, datacenter
  953. ASSERT(CanInstallAppServer() || !IsItAppServer());
  954. // we cannot be in RA mode for Professional.
  955. ASSERT(IsServer() || !IsItRemoteAdmin());
  956. // if permissions mode is TS4 compatible, it must be appserver
  957. ASSERT((CurrentPermMode() != PERM_TS4) || IsItAppServer());
  958. // we should never allwe connections on Personal
  959. ASSERT(!IsPersonal() || !GetCurrentConnAllowed ());
  960. }
  961. return TRUE;
  962. }
  963. BOOL TSState::IsCheckedBuild () const
  964. {
  965. #ifdef DBG
  966. return TRUE;
  967. #else
  968. return FALSE;
  969. #endif
  970. }