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.

1560 lines
42 KiB

  1. // Copyright (c) 1998 - 1999 Microsoft Corporation
  2. #include "stdafx.h"
  3. #include <iostream.h>
  4. #include <fstream.h>
  5. #include <strstrea.h>
  6. #include <dsrole.h>
  7. //
  8. // global utilities and veraibles.
  9. //
  10. char szOutput[2048];
  11. ostrstream szMoreInfo(szOutput, 4096);
  12. TCHAR *ReturnBuffer()
  13. {
  14. static TCHAR szReturnTchar[512];
  15. return szReturnTchar;
  16. }
  17. const OSVERSIONINFOEX *GetOSVersionInfo()
  18. {
  19. static OSVERSIONINFOEX gOsVersion;
  20. static bGotOnce = FALSE;
  21. if (!bGotOnce)
  22. {
  23. ZeroMemory(&gOsVersion, sizeof(OSVERSIONINFOEX));
  24. gOsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  25. GetVersionEx( (LPOSVERSIONINFO ) &gOsVersion);
  26. bGotOnce = TRUE;
  27. }
  28. return &gOsVersion;
  29. }
  30. // #include <strstream>
  31. #include "winsock2.h"
  32. // ostringstream sz
  33. #ifndef UNREFERENCED_PARAMETER
  34. #define UNREFERENCED_PARAMETER(P) (P)
  35. #endif
  36. #define OLD_VER_SET_CONDITION(_m_,_t_,_c_) _m_=(_m_|(_c_<<(1<<_t_)))
  37. BOOL CheckifBinaryisSigned (TCHAR *szFile); // from tscert.cpp
  38. BOOL EnumerateLicenseServers (); // from timebomb.cpp
  39. TCHAR *IsBetaSystem ();
  40. BOOL HasLicenceGracePeriodExpired (); // from timebomb.cpp
  41. BOOL ExtractAllTSEvents();
  42. BOOL ValidateProductSuite (LPSTR SuiteName);
  43. BOOL IsTerminalServicesEnabled ( VOID );
  44. DWORD IsStringInMultiString(HKEY hkey, LPCTSTR szkey, LPCTSTR szvalue, LPCTSTR szCheckForString, BOOL *pbFound);
  45. BOOL DoesHydraKeysExists ();
  46. TCHAR *IsServer ();
  47. BOOL IsKernelTSEnable ();
  48. BOOL TSEnabled ();
  49. BOOL DoesProductSuiteContainTS ();
  50. BOOL IsTerminalServerRegistryOk ();
  51. TCHAR *IsTerminalServiceStartBitSet ();
  52. BOOL IsTermDDStartBitSet ();
  53. BOOL GetTSOCLogFileName (char *strFileName, UINT uiSize);
  54. BOOL DidTsOCgetCompleteInstallationMessage ();
  55. BOOL FileExists (char *pszFullNameAndPath);
  56. BOOL IsTSOClogPresent ();
  57. BOOL DidOCMInstallTSEnable();
  58. TCHAR *IsClusteringInstalled ();
  59. BOOL IsRemoteAdminMode ();
  60. BOOL CheckModeRegistry (BOOL bAppCompat);
  61. BOOL IsTerminalServiceRunning ();
  62. BOOL CheckVideoKeys ();
  63. BOOL CheckModePermissions(DWORD *pdwSecurtyMode);
  64. BOOL IsFile128Bit(LPTSTR szFile, BOOL *pb128Bit);
  65. ULONG RDPDRINST_DetectInstall(); // defined in drdetect.cpp
  66. BOOL IsAudioOk( VOID );
  67. TCHAR *aszStack[] = {
  68. // _T("noexport\%SystemRoot%\\system32\\drivers\\rdpwdd.sys"),
  69. _T("%SystemRoot%\\system32\\drivers\\termdd.sys"),
  70. _T("%SystemRoot%\\system32\\drivers\\tdasync.sys"),
  71. _T("%SystemRoot%\\system32\\drivers\\tdipx.sys"),
  72. _T("%SystemRoot%\\system32\\drivers\\tdnetb.sys"),
  73. _T("%SystemRoot%\\system32\\drivers\\tdpipe.sys"),
  74. _T("%SystemRoot%\\system32\\drivers\\tdspx.sys"),
  75. _T("%SystemRoot%\\system32\\drivers\\tdtcp.sys"),
  76. _T("%SystemRoot%\\system32\\drivers\\rdpwd.sys"),
  77. _T("%SystemRoot%\\system32\\rdpdd.dll"),
  78. _T("%SystemRoot%\\system32\\rdpwsx.dll")
  79. };
  80. TCHAR Version[256];
  81. TCHAR *GetTSVersion()
  82. {
  83. CRegistry oRegTermsrv;
  84. DWORD cbVersion = 0;
  85. LPTSTR szVersion = NULL;
  86. if ((ERROR_SUCCESS == oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ)) &&
  87. (ERROR_SUCCESS == oRegTermsrv.ReadRegString(_T("ProductVersion"), &szVersion, &cbVersion)))
  88. {
  89. _tcscpy(Version, szVersion);
  90. return Version;
  91. }
  92. return _T("Error finding Version.");
  93. }
  94. BOOL IsIt50TS()
  95. {
  96. return (0 == _tcsicmp(Version, _T("5.0")));
  97. }
  98. BOOL IsIt51TS()
  99. {
  100. return (0 == _tcsicmp(Version, _T("5.1")));
  101. }
  102. TCHAR *IsLicenceGracePeriodOk ()
  103. {
  104. return (HasLicenceGracePeriodExpired () ? _T("Yep, Its expired") : _T("Its Not expired"));
  105. }
  106. BOOL Check_termdd()
  107. {
  108. return CheckifBinaryisSigned(_T("%SystemRoot%\\system32\\drivers\\termdd.sys"));
  109. }
  110. BOOL Check_tdasync()
  111. {
  112. return CheckifBinaryisSigned(_T("%SystemRoot%\\system32\\drivers\\tdasync.sys"));
  113. }
  114. BOOL Check_tdipx()
  115. {
  116. return CheckifBinaryisSigned(_T("%SystemRoot%\\system32\\drivers\\tdipx.sys"));
  117. }
  118. BOOL Check_tdnetb()
  119. {
  120. return CheckifBinaryisSigned(_T("%SystemRoot%\\system32\\drivers\\tdnetb.sys"));
  121. }
  122. BOOL Check_tdpipe()
  123. {
  124. return CheckifBinaryisSigned(_T("%SystemRoot%\\system32\\drivers\\tdpipe.sys"));
  125. }
  126. BOOL Check_tdspx()
  127. {
  128. return CheckifBinaryisSigned(_T("%SystemRoot%\\system32\\drivers\\tdspx.sys"));
  129. }
  130. BOOL Check_tdtcp()
  131. {
  132. return CheckifBinaryisSigned(_T("%SystemRoot%\\system32\\drivers\\tdtcp.sys"));
  133. }
  134. BOOL Check_rdpwd()
  135. {
  136. return CheckifBinaryisSigned(_T("%SystemRoot%\\system32\\drivers\\rdpwd.sys"));
  137. }
  138. BOOL Check_rdpdd()
  139. {
  140. return CheckifBinaryisSigned(_T("%SystemRoot%\\system32\\rdpdd.dll"));
  141. }
  142. BOOL Check_rdpwsx()
  143. {
  144. return CheckifBinaryisSigned(_T("%SystemRoot%\\system32\\rdpwsx.dll"));
  145. }
  146. BOOL IsRdpDrInstalledProperly ()
  147. {
  148. return RDPDRINST_DetectInstall();
  149. }
  150. TCHAR *GetModePermissions()
  151. {
  152. CRegistry reg;
  153. DWORD dwSecurityMode;
  154. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ))
  155. {
  156. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("TSUserEnabled"), &dwSecurityMode))
  157. {
  158. if (dwSecurityMode == 0)
  159. {
  160. return _T("Its W2k Compatible");
  161. }
  162. else if (dwSecurityMode == 1)
  163. {
  164. return _T("Its TS4 Compatible");
  165. }
  166. else
  167. {
  168. szMoreInfo << "SYSTEM\\CurrentControlSet\\Control\\Terminal Server/TSUserEnabled has wrong value" << dwSecurityMode << endl;
  169. return NULL;
  170. }
  171. }
  172. }
  173. return NULL;
  174. }
  175. BOOL CheckModePermissions (DWORD *pdwSecurtyMode)
  176. {
  177. // PERM_WIN2K = 0,
  178. // PERM_TS4 = 1
  179. CRegistry reg;
  180. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ))
  181. {
  182. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("TSUserEnabled"), pdwSecurtyMode))
  183. {
  184. return (*pdwSecurtyMode== 0) || (*pdwSecurtyMode== 1);
  185. }
  186. }
  187. return FALSE;
  188. }
  189. TCHAR *GetCypherStrenthOnRdpwd ()
  190. {
  191. BOOL bFile128bit;
  192. if ( IsFile128Bit(_T("%SystemRoot%\\system32\\drivers\\rdpwd.sys"), &bFile128bit) )
  193. {
  194. return bFile128bit ? _T("128 Bit") : _T("56 Bit");
  195. }
  196. else
  197. {
  198. return NULL;
  199. }
  200. }
  201. BOOL IsFile128Bit(LPTSTR szFile, BOOL *pb128Bit)
  202. {
  203. USES_CONVERSION;
  204. DWORD dwHandle;
  205. TCHAR szFullFile[MAX_PATH +1];
  206. BOOL bSuccess = FALSE;
  207. if (ExpandEnvironmentStrings(szFile, szFullFile, MAX_PATH))
  208. {
  209. if (FileExists(T2A(szFullFile)))
  210. {
  211. DWORD dwSize = GetFileVersionInfoSize(szFullFile, &dwHandle);
  212. if (dwSize > 0)
  213. {
  214. BYTE *pbData = new BYTE[dwSize];
  215. if (pbData)
  216. {
  217. if (GetFileVersionInfo(szFullFile, 0, dwSize, pbData))
  218. {
  219. TCHAR *szFileDescription;
  220. UINT uiLen = 0;
  221. if (VerQueryValue(pbData, _T("\\StringFileInfo\\040904B0\\FileDescription"), (LPVOID *)&szFileDescription, &uiLen))
  222. {
  223. if (_tcsstr(szFileDescription, _T("Not for Export")))
  224. {
  225. *pb128Bit = TRUE;
  226. bSuccess = TRUE;
  227. }
  228. else if (_tcsstr(szFileDescription, _T("Export Version")))
  229. {
  230. *pb128Bit = FALSE;
  231. bSuccess = TRUE;
  232. }
  233. }
  234. }
  235. delete [] pbData;
  236. }
  237. }
  238. }
  239. }
  240. return bSuccess;
  241. }
  242. BOOL ValidateProductSuite (LPSTR SuiteName)
  243. {
  244. BOOL rVal = FALSE;
  245. LONG Rslt;
  246. HKEY hKey = NULL;
  247. DWORD Type = 0;
  248. DWORD Size = 0;
  249. LPSTR ProductSuite = NULL;
  250. LPSTR p;
  251. Rslt = RegOpenKeyA(
  252. HKEY_LOCAL_MACHINE,
  253. "System\\CurrentControlSet\\Control\\ProductOptions",
  254. &hKey
  255. );
  256. if (Rslt != ERROR_SUCCESS)
  257. goto exit;
  258. Rslt = RegQueryValueExA( hKey, "ProductSuite", NULL, &Type, NULL, &Size );
  259. if (Rslt != ERROR_SUCCESS || !Size)
  260. goto exit;
  261. ProductSuite = (LPSTR) LocalAlloc( LPTR, Size );
  262. if (!ProductSuite)
  263. goto exit;
  264. Rslt = RegQueryValueExA( hKey, "ProductSuite", NULL, &Type,
  265. (LPBYTE) ProductSuite, &Size );
  266. if (Rslt != ERROR_SUCCESS || Type != REG_MULTI_SZ)
  267. goto exit;
  268. p = ProductSuite;
  269. while (*p)
  270. {
  271. if (lstrcmpA( p, SuiteName ) == 0)
  272. {
  273. rVal = TRUE;
  274. break;
  275. }
  276. p += (lstrlenA( p ) + 1);
  277. }
  278. exit:
  279. if (ProductSuite)
  280. LocalFree( ProductSuite );
  281. if (hKey)
  282. RegCloseKey( hKey );
  283. return rVal;
  284. }
  285. BOOL IsTerminalServicesEnabled( VOID )
  286. {
  287. BOOL bResult = FALSE;
  288. DWORD dwVersion;
  289. OSVERSIONINFOEXA osVersionInfo;
  290. DWORDLONG dwlConditionMask = 0;
  291. HMODULE hmodK32 = NULL;
  292. typedef ULONGLONG (*PFnVerSetConditionMask) ( ULONGLONG, ULONG, UCHAR );
  293. typedef BOOL (*PFnVerifyVersionInfoA) (POSVERSIONINFOEXA, DWORD, DWORDLONG);
  294. PFnVerSetConditionMask pfnVerSetConditionMask;
  295. PFnVerifyVersionInfoA pfnVerifyVersionInfoA;
  296. dwVersion = GetVersion();
  297. /* are we running NT ? */
  298. if (!(dwVersion & 0x80000000))
  299. {
  300. // Is it NT 50 or greater ?
  301. if (LOBYTE(LOWORD(dwVersion)) > 4)
  302. {
  303. /* In NT5 we need to use the Product Suite APIs
  304. Don't static link because it won't load on non-NT5 systems */
  305. hmodK32 = GetModuleHandleA( "KERNEL32.DLL" );
  306. if (hmodK32)
  307. {
  308. pfnVerSetConditionMask = (PFnVerSetConditionMask )GetProcAddress( hmodK32, "VerSetConditionMask");
  309. if (pfnVerSetConditionMask)
  310. {
  311. /* get the condition mask. */
  312. dwlConditionMask = (*pfnVerSetConditionMask)(dwlConditionMask, VER_SUITENAME, VER_AND);
  313. pfnVerifyVersionInfoA = (PFnVerifyVersionInfoA)GetProcAddress( hmodK32, "VerifyVersionInfoA") ;
  314. if (pfnVerifyVersionInfoA != NULL)
  315. {
  316. ZeroMemory(&osVersionInfo, sizeof(osVersionInfo));
  317. osVersionInfo.dwOSVersionInfoSize = sizeof(osVersionInfo);
  318. osVersionInfo.wSuiteMask = VER_SUITE_TERMINAL;
  319. bResult = (*pfnVerifyVersionInfoA)(
  320. &osVersionInfo,
  321. VER_SUITENAME,
  322. dwlConditionMask);
  323. }
  324. }
  325. }
  326. }
  327. else
  328. {
  329. /* This is NT 40 */
  330. bResult = ValidateProductSuite( "Terminal Server" );
  331. }
  332. }
  333. return bResult;
  334. }
  335. /*--------------------------------------------------------------------------------------------------------
  336. * DWORD IsStringInMultiString(HKEY hkey, LPCTSTR szkey, LPCTSTR szvalue, LPCTSTR szCheckForString, BOOL *pbFound)
  337. * checks if parameter string exists in given multistring.
  338. * returns error code.
  339. * -------------------------------------------------------------------------------------------------------*/
  340. DWORD IsStringInMultiString(HKEY hkey, LPCTSTR szkey, LPCTSTR szvalue, LPCTSTR szCheckForString, BOOL *pbFound)
  341. {
  342. ASSERT(szkey && *szkey);
  343. ASSERT(szvalue && *szvalue);
  344. ASSERT(szCheckForString&& *szCheckForString);
  345. ASSERT(*szkey != '\\');
  346. ASSERT(pbFound);
  347. // not yet found.
  348. *pbFound = FALSE;
  349. CRegistry reg;
  350. DWORD dwError = reg.OpenKey(hkey, szkey, KEY_READ); // open up the required key.
  351. if (dwError == NO_ERROR)
  352. {
  353. LPTSTR szSuiteValue;
  354. DWORD dwSize;
  355. dwError = reg.ReadRegMultiString(szvalue, &szSuiteValue, &dwSize);
  356. if (dwError == NO_ERROR)
  357. {
  358. LPCTSTR pTemp = szSuiteValue;
  359. while(_tcslen(pTemp) > 0 )
  360. {
  361. if (_tcscmp(pTemp, szCheckForString) == 0)
  362. {
  363. *pbFound = TRUE;
  364. break;
  365. }
  366. pTemp += _tcslen(pTemp) + 1; // point to the next string within the multistring.
  367. if ( DWORD(pTemp - szSuiteValue) > (dwSize / sizeof(TCHAR)))
  368. break; // temporary pointer passes the size of the szSuiteValue something is wrong with szSuiteValue.
  369. }
  370. }
  371. }
  372. return dwError;
  373. }
  374. BOOL DoesHydraKeysExists()
  375. {
  376. BOOL bStringExists = FALSE;
  377. DWORD dw = IsStringInMultiString(
  378. HKEY_LOCAL_MACHINE,
  379. _T("SYSTEM\\CurrentControlSet\\Control\\ProductOptions"),
  380. _T("ProductSuite"),
  381. _T("Terminal Server"),
  382. &bStringExists);
  383. return (dw == ERROR_SUCCESS) && bStringExists;
  384. }
  385. TCHAR *IsItAppServer ()
  386. {
  387. return ((GetOSVersionInfo()->wSuiteMask & VER_SUITE_TERMINAL) &&
  388. !(GetOSVersionInfo()->wSuiteMask & VER_SUITE_SINGLEUSERTS)) ? _T("Yes") : _T("No");
  389. }
  390. BOOL IsItServer ()
  391. {
  392. return GetOSVersionInfo()->wProductType != VER_NT_WORKSTATION;
  393. }
  394. TCHAR *GetProductType ()
  395. {
  396. BYTE wProductType = GetOSVersionInfo()->wProductType;
  397. _tcscpy(ReturnBuffer(), _T(""));
  398. if (wProductType == VER_NT_WORKSTATION)
  399. {
  400. _tcscat(ReturnBuffer(), _T("VER_NT_WORKSTATION "));
  401. }
  402. if (wProductType == VER_NT_DOMAIN_CONTROLLER)
  403. {
  404. _tcscat(ReturnBuffer(), _T("VER_NT_DOMAIN_CONTROLLER"));
  405. }
  406. if (wProductType == VER_NT_SERVER)
  407. {
  408. _tcscat(ReturnBuffer(), _T("VER_NT_SERVER"));
  409. }
  410. return ReturnBuffer();
  411. }
  412. TCHAR *GetProductSuite ()
  413. {
  414. WORD wProductSuite = GetOSVersionInfo()->wSuiteMask;
  415. _tcscpy(ReturnBuffer(), _T(""));
  416. if (wProductSuite & VER_SERVER_NT)
  417. {
  418. _tcscat(ReturnBuffer(), _T("VER_SERVER_NT "));
  419. }
  420. if (wProductSuite & VER_WORKSTATION_NT)
  421. {
  422. _tcscat(ReturnBuffer(), _T("VER_WORKSTATION_NT "));
  423. }
  424. if (wProductSuite & VER_SUITE_SMALLBUSINESS)
  425. {
  426. _tcscat(ReturnBuffer(), _T("VER_SUITE_SMALLBUSINESS "));
  427. }
  428. if (wProductSuite & VER_SUITE_ENTERPRISE)
  429. {
  430. _tcscat(ReturnBuffer(), _T("VER_SUITE_ENTERPRISE "));
  431. }
  432. if (wProductSuite & VER_SUITE_BACKOFFICE)
  433. {
  434. _tcscat(ReturnBuffer(), _T("VER_SUITE_BACKOFFICE "));
  435. }
  436. if (wProductSuite & VER_SUITE_COMMUNICATIONS)
  437. {
  438. _tcscat(ReturnBuffer(), _T("VER_SUITE_COMMUNICATIONS "));
  439. }
  440. if (wProductSuite & VER_SUITE_TERMINAL)
  441. {
  442. _tcscat(ReturnBuffer(), _T("VER_SUITE_TERMINAL "));
  443. }
  444. if (wProductSuite & VER_SUITE_SMALLBUSINESS_RESTRICTED)
  445. {
  446. _tcscat(ReturnBuffer(), _T("VER_SUITE_SMALLBUSINESS_RESTRICTED "));
  447. }
  448. if (wProductSuite & VER_SUITE_EMBEDDEDNT)
  449. {
  450. _tcscat(ReturnBuffer(), _T("VER_SUITE_EMBEDDEDNT "));
  451. }
  452. if (wProductSuite & VER_SUITE_DATACENTER)
  453. {
  454. _tcscat(ReturnBuffer(), _T("VER_SUITE_DATACENTER "));
  455. }
  456. if (wProductSuite & VER_SUITE_SINGLEUSERTS)
  457. {
  458. _tcscat(ReturnBuffer(), _T("VER_SUITE_SINGLEUSERTS "));
  459. }
  460. if (wProductSuite & VER_SUITE_PERSONAL)
  461. {
  462. _tcscat(ReturnBuffer(), _T("VER_SUITE_PERSONAL "));
  463. }
  464. return ReturnBuffer();
  465. }
  466. TCHAR *IsServer ()
  467. {
  468. return IsItServer() ? _T("Its a Server") : _T("Its a WorkStation");
  469. }
  470. BOOL IsKernelTSEnable ()
  471. {
  472. return IsTerminalServicesEnabled();
  473. }
  474. BOOL TSEnabled ()
  475. {
  476. CRegistry reg;
  477. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ))
  478. {
  479. DWORD dwTSEnabled = 0;
  480. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("TSEnabled"), &dwTSEnabled))
  481. {
  482. return dwTSEnabled == 1;
  483. }
  484. }
  485. return FALSE;
  486. }
  487. BOOL DoesProductSuiteContainTS ()
  488. {
  489. return DoesHydraKeysExists ();
  490. }
  491. BOOL IsTerminalServerRegistryOk ()
  492. {
  493. CRegistry reg1;
  494. CRegistry reg2;
  495. CRegistry reg3;
  496. return
  497. (ERROR_SUCCESS == reg1.OpenKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ)) &&
  498. (ERROR_SUCCESS == reg2.OpenKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\WinStations"), KEY_READ)) &&
  499. (ERROR_SUCCESS == reg3.OpenKey(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\Terminal Server"), KEY_READ));
  500. }
  501. TCHAR *GetWinstationList ()
  502. {
  503. TCHAR szWinstationList[256];
  504. BOOL bFoundNonConsoleWinstation = FALSE;
  505. _tcscpy(szWinstationList, _T(""));
  506. CRegistry reg2;
  507. if (ERROR_SUCCESS == reg2.OpenKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\WinStations"), KEY_READ))
  508. {
  509. LPTSTR szWinstation;
  510. DWORD dwSize;
  511. BOOL bFirst = TRUE;
  512. if (ERROR_SUCCESS == reg2.GetFirstSubKey(&szWinstation, &dwSize))
  513. {
  514. do
  515. {
  516. if (0 != _tcsicmp(szWinstation, _T("Console")))
  517. {
  518. bFoundNonConsoleWinstation = TRUE;
  519. }
  520. if (!bFirst)
  521. {
  522. _tcscat(szWinstationList, _T(", "));
  523. }
  524. _tcscat(szWinstationList, szWinstation);
  525. bFirst = FALSE;
  526. }
  527. while (ERROR_SUCCESS == reg2.GetNextSubKey(&szWinstation, &dwSize));
  528. }
  529. }
  530. if (_tcslen(szWinstationList) == 0)
  531. {
  532. _tcscpy(szWinstationList, _T("Error, No winstations found."));
  533. }
  534. if (!bFoundNonConsoleWinstation)
  535. {
  536. szMoreInfo << "ERROR, No non Console Winstation not found" << endl;
  537. }
  538. _tcscpy(ReturnBuffer(), szWinstationList);
  539. return ReturnBuffer();
  540. }
  541. TCHAR *IsTerminalServiceStartBitSet ()
  542. {
  543. CRegistry reg;
  544. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\TermService"), KEY_READ))
  545. {
  546. DWORD dwTermServStartBit = 0;
  547. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("Start"), &dwTermServStartBit))
  548. {
  549. switch (dwTermServStartBit)
  550. {
  551. case 2:
  552. return _T("AutoStart");
  553. break;
  554. case 3:
  555. return _T("Manual Start");
  556. break;
  557. case 4:
  558. return _T("Error, Disabled");
  559. break;
  560. default:
  561. return _T("ERROR:Wrong value for startbit");
  562. }
  563. }
  564. }
  565. return _T("Error, Reading startbig");
  566. }
  567. BOOL IsTermDDStartBitSet ()
  568. {
  569. CRegistry reg;
  570. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\TermDD"), KEY_READ))
  571. {
  572. DWORD dwTermDDStartBit = 0;
  573. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("Start"), &dwTermDDStartBit))
  574. {
  575. return dwTermDDStartBit == 2;
  576. }
  577. }
  578. return FALSE;
  579. }
  580. TCHAR *AreEffectiveConnectionAllowed ()
  581. {
  582. HMODULE hmodRegAPI = LoadLibrary( _T("RegApi.dll") );
  583. if (hmodRegAPI)
  584. {
  585. typedef BOOLEAN (*PFDenyConnectionPolicy) ();
  586. PFDenyConnectionPolicy pfnDenyConnectionPolicy;
  587. pfnDenyConnectionPolicy = (PFDenyConnectionPolicy) GetProcAddress( hmodRegAPI, "RegDenyTSConnectionsPolicy");
  588. if (pfnDenyConnectionPolicy)
  589. {
  590. return (*pfnDenyConnectionPolicy)() ? _T("Not Allowed") : _T("Allowed");
  591. }
  592. else
  593. {
  594. szMoreInfo << "Failed to get proc RegDenyTSConnectionsPolicy" << endl;
  595. return _T("Failed");
  596. }
  597. }
  598. else
  599. {
  600. szMoreInfo << "Failed to Load regapi.dll" << endl;
  601. return _T("Failed");
  602. }
  603. }
  604. TCHAR *AreConnectionsAllowed ()
  605. {
  606. DWORD dwError;
  607. CRegistry oRegTermsrv;
  608. dwError = oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ);
  609. if (ERROR_SUCCESS == dwError)
  610. {
  611. DWORD dwDenyConnect;
  612. dwError = oRegTermsrv.ReadRegDWord(_T("fDenyTSConnections"), &dwDenyConnect);
  613. if (ERROR_SUCCESS == dwError)
  614. {
  615. return dwDenyConnect ? _T("No, Not allowed") : _T("Yes");
  616. }
  617. }
  618. //
  619. // could not read registry, It means - for 51 connection not allowed. For 50 Connections allowed.
  620. //
  621. return IsIt51TS() ? _T("Error, Value not found") : _T("Yes");
  622. }
  623. BOOL GetTSOCLogFileName(char *strFileName, UINT uiSize)
  624. {
  625. if (!GetSystemWindowsDirectoryA(strFileName, uiSize))
  626. return FALSE;
  627. strcat(strFileName, "\\tsoc.log");
  628. ASSERT(strlen(strFileName) < uiSize);
  629. return TRUE;
  630. }
  631. char *IncompleteMessage = "Error:TSOC Did not get OC_COMPLETE_INSTALLATION.";
  632. BOOL DidTsOCgetCompleteInstallationMessage ()
  633. {
  634. if (!IsTSOClogPresent())
  635. {
  636. szMoreInfo << "tsoc.log does not exist." << endl;
  637. return FALSE;
  638. }
  639. char strTSOCLog[256];
  640. GetTSOCLogFileName(strTSOCLog, 256);
  641. ifstream ifSrc(strTSOCLog);
  642. if(!ifSrc)
  643. {
  644. szMoreInfo << "Failed to open tsoc.log file." << endl;
  645. return FALSE;
  646. }
  647. char tempSrc[256];
  648. while(!ifSrc.eof())
  649. {
  650. ifSrc.getline(tempSrc, 256);
  651. if (strstr(tempSrc, IncompleteMessage))
  652. {
  653. return FALSE;
  654. }
  655. }
  656. return TRUE;
  657. }
  658. BOOL FileExists(char *pszFullNameAndPath)
  659. {
  660. ASSERT(pszFullNameAndPath);
  661. if (pszFullNameAndPath && pszFullNameAndPath[0])
  662. {
  663. HANDLE hFile = CreateFileA(pszFullNameAndPath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
  664. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  665. if (hFile != INVALID_HANDLE_VALUE)
  666. {
  667. CloseHandle(hFile);
  668. return TRUE;
  669. }
  670. }
  671. return FALSE;
  672. }
  673. BOOL IsTSOClogPresent ()
  674. {
  675. char strTSOCLog[256];
  676. GetTSOCLogFileName(strTSOCLog, 256);
  677. return FileExists(strTSOCLog);
  678. }
  679. BOOL DidOCMInstallTSEnable()
  680. {
  681. CRegistry reg;
  682. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\OC Manager\\SubComponents"), KEY_READ))
  683. {
  684. DWORD dwTSEnabled = 0;
  685. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("tsenable"), &dwTSEnabled))
  686. {
  687. return dwTSEnabled == 1;
  688. }
  689. }
  690. return FALSE;
  691. }
  692. TCHAR *IsClusteringInstalled ()
  693. {
  694. DWORD dwClusterState;
  695. if (ERROR_SUCCESS == GetNodeClusterState(NULL, &dwClusterState))
  696. {
  697. if (dwClusterState != ClusterStateNotInstalled)
  698. {
  699. return _T("***Failed. Clustering is installed, this is not compatible with Terminal Server.");
  700. }
  701. }
  702. return _T("Passed");
  703. }
  704. TCHAR *GetTSMode (void)
  705. {
  706. return IsRemoteAdminMode() ? _T("Remote Admin") : _T("Application Server");
  707. }
  708. BOOL IsRemoteAdminMode ()
  709. {
  710. // HKLM ,"SYSTEM\CurrentControlSet\Control\Terminal Server","TSAppCompat",0x00010001,0x0
  711. CRegistry reg;
  712. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ))
  713. {
  714. DWORD dwAppCompat = 1;
  715. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("TSAppCompat"), &dwAppCompat))
  716. {
  717. return dwAppCompat == 0;
  718. }
  719. else
  720. {
  721. // if the registry TSAppCompat does not exist it means we are in app server mode.
  722. return FALSE;
  723. }
  724. }
  725. else
  726. {
  727. szMoreInfo << "ERROR:SYSTEM\\CurrentControlSet\\Control\\Terminal Server not found!" << endl;
  728. }
  729. // this return is bogus.
  730. return TRUE;
  731. }
  732. BOOL VerifyModeRegistry()
  733. {
  734. return CheckModeRegistry(!IsRemoteAdminMode());
  735. }
  736. BOOL CheckModeRegistry (BOOL bAppCompat)
  737. {
  738. USES_CONVERSION;
  739. BOOL bOk = TRUE;
  740. CRegistry reg;
  741. if (IsItServer())
  742. {
  743. CRegistry reg1;
  744. // check registry value
  745. // for appcompat mode
  746. //HKLM ,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","AppSetup",0x00000000,"UsrLogon.Cmd"
  747. // and for remote admin mode
  748. //HKLM ,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","AppSetup",0x00000000,""
  749. if ( ERROR_SUCCESS == reg1.OpenKey( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), KEY_READ))
  750. {
  751. LPTSTR str;
  752. DWORD dwSize;
  753. if (ERROR_SUCCESS == reg1.ReadRegString(_T("AppSetup"), &str, &dwSize))
  754. {
  755. if (bAppCompat)
  756. {
  757. if (_tcsicmp(str, _T("UsrLogon.Cmd")) != 0)
  758. {
  759. bOk = FALSE;
  760. szMoreInfo << "ERROR: Wrong value (" << T2A(str) << ") for AppSetup, contact makarp/breenh" << endl;
  761. }
  762. }
  763. else
  764. {
  765. if (_tcslen(str) != 0)
  766. {
  767. bOk = FALSE;
  768. szMoreInfo << "ERROR: Wrong value (" << T2A(str) << ") for AppSetup, contact makarp/breenh" << endl;
  769. }
  770. }
  771. }
  772. else
  773. {
  774. szMoreInfo << "ERROR reading appsetup registry" << endl;
  775. bOk = FALSE;
  776. }
  777. }
  778. else
  779. {
  780. szMoreInfo << "ERROR:reading SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" << endl;
  781. bOk = FALSE;
  782. }
  783. }
  784. // check registry value
  785. // for appcompat mode
  786. //HKLM ,"SYSTEM\CurrentControlSet\Control\PriorityControl","Win32PrioritySeparation", 0x00010001,0x26
  787. // and for remote admin mode
  788. //HKLM ,"SYSTEM\CurrentControlSet\Control\PriorityControl","Win32PrioritySeparation", 0x00010001,0x18
  789. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\PriorityControl"), KEY_READ))
  790. {
  791. DWORD dwPriority;
  792. if (ERROR_SUCCESS == reg.ReadRegDWord(_T("Win32PrioritySeparation"), &dwPriority))
  793. {
  794. if (bAppCompat)
  795. {
  796. if (0x26 != dwPriority)
  797. {
  798. bOk = FALSE;
  799. szMoreInfo << "ERROR: Wrong Win32PrioritySeparation (" << dwPriority << ")" << endl;
  800. }
  801. }
  802. else if (IsItServer())
  803. {
  804. if (0x18 != dwPriority)
  805. {
  806. bOk = FALSE;
  807. szMoreInfo << "ERROR: Wrong Win32PrioritySeparation (" << dwPriority << ")" << endl;
  808. }
  809. }
  810. }
  811. else
  812. {
  813. bOk = FALSE;
  814. szMoreInfo << "ERROR:Reading Win32PrioritySeparation registry" << endl;
  815. }
  816. }
  817. else
  818. {
  819. bOk = FALSE;
  820. szMoreInfo << "ERROR:Reading PriorityControl registry" << endl;
  821. }
  822. // check registry value
  823. // for appcompat mode
  824. //HKLM ,"SYSTEM\CurrentControlSet\Control\Terminal Server","IdleWinStationPoolCount",0x00010001,0x2
  825. // and for remote admin mode
  826. //HKLM ,"SYSTEM\CurrentControlSet\Control\Terminal Server","IdleWinStationPoolCount",0x00010001,0x0
  827. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ))
  828. {
  829. DWORD dwIdleWinstations;
  830. if (ERROR_SUCCESS == reg.ReadRegDWord(_T("IdleWinStationPoolCount"), &dwIdleWinstations))
  831. {
  832. if (bAppCompat)
  833. {
  834. if (0x2 != dwIdleWinstations)
  835. {
  836. bOk = FALSE;
  837. szMoreInfo << "ERROR: Wrong IdleWinStationPoolCount (" << dwIdleWinstations << ")" << endl;
  838. }
  839. }
  840. else
  841. {
  842. if (0 != dwIdleWinstations)
  843. {
  844. bOk = FALSE;
  845. szMoreInfo << "ERROR: Wrong IdleWinStationPoolCount (" << dwIdleWinstations << ")" << endl;
  846. }
  847. }
  848. }
  849. else
  850. {
  851. bOk = FALSE;
  852. szMoreInfo << "ERROR:Reading IdleWinStationPoolCount registry" << endl;
  853. }
  854. }
  855. else
  856. {
  857. bOk = FALSE;
  858. szMoreInfo << "SYSTEM\\CurrentControlSet\\Control\\Terminal Server" << endl;
  859. }
  860. return bOk;
  861. }
  862. BOOL IsTerminalServiceRunning ()
  863. {
  864. BOOL bReturn = FALSE;
  865. SC_HANDLE hServiceController = OpenSCManager(NULL, NULL, GENERIC_READ);
  866. if (hServiceController)
  867. {
  868. SC_HANDLE hTermServ = OpenService(hServiceController, _T("TermService"), SERVICE_QUERY_STATUS);
  869. if (hTermServ)
  870. {
  871. SERVICE_STATUS tTermServStatus;
  872. if (QueryServiceStatus(hTermServ, &tTermServStatus))
  873. {
  874. bReturn = (tTermServStatus.dwCurrentState == SERVICE_RUNNING);
  875. }
  876. else
  877. {
  878. szMoreInfo << "Failed to get service status, Error = " << GetLastError() << endl;
  879. }
  880. VERIFY(CloseServiceHandle(hTermServ));
  881. }
  882. else
  883. {
  884. szMoreInfo << "Failed to open TermServ service, Error = " << GetLastError() << endl;
  885. }
  886. VERIFY(CloseServiceHandle(hServiceController));
  887. }
  888. else
  889. {
  890. szMoreInfo << "Failed to Open Service Controller, Error = " << GetLastError() << endl;
  891. }
  892. return bReturn;
  893. }
  894. BOOL CheckVideoKeys ()
  895. {
  896. // HKLM ,"SYSTEM\CurrentControlSet\Control\Terminal Server\VIDEO\rdpdd","VgaCompatible",0x00000000,"\Device\Video0"
  897. // HKLM ,"SYSTEM\CurrentControlSet\Control\Terminal Server\VIDEO\rdpdd","\Device\Video0",0x00000000,"\REGISTRY\Machine\System\ControlSet001\Services\RDPDD\Device0"
  898. CRegistry reg;
  899. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\VIDEO\\rdpdd"), KEY_READ))
  900. {
  901. LPTSTR str = 0;
  902. DWORD dwSize = 0;
  903. if (ERROR_SUCCESS == reg.ReadRegString(_T("VgaCompatible"), &str, &dwSize))
  904. {
  905. if (0 == _tcsicmp(str, _T("\\Device\\Video0")))
  906. {
  907. if (ERROR_SUCCESS == reg.ReadRegString(_T("\\Device\\Video0"), &str, &dwSize))
  908. {
  909. if ((0 == _tcsicmp(str, _T("\\REGISTRY\\Machine\\System\\ControlSet001\\Services\\RDPDD\\Device0"))) ||
  910. (0 == _tcsicmp(str, _T("\\REGISTRY\\Machine\\System\\CurrentControlSet\\Services\\RDPDD\\Device0"))))
  911. {
  912. return TRUE;
  913. }
  914. else
  915. {
  916. }
  917. }
  918. else
  919. {
  920. }
  921. }
  922. else
  923. {
  924. }
  925. }
  926. else
  927. {
  928. }
  929. }
  930. else
  931. {
  932. }
  933. return FALSE;
  934. }
  935. TCHAR szCompName[256];
  936. TCHAR *GetCompName ()
  937. {
  938. DWORD dwCompName = 256;
  939. if (GetComputerName(szCompName, &dwCompName))
  940. {
  941. return szCompName;
  942. }
  943. return NULL;
  944. }
  945. TCHAR szDomNameWorkgroup[] = _T("<Workgroup>");
  946. TCHAR szDomNameUnknown[] = _T("<Unknown>");
  947. TCHAR *GetDomName ()
  948. {
  949. DSROLE_PRIMARY_DOMAIN_INFO_BASIC *pDomainInfo = NULL;
  950. DWORD dwErr;
  951. //
  952. // Check if we're in a workgroup
  953. //
  954. dwErr = DsRoleGetPrimaryDomainInformation(NULL,
  955. DsRolePrimaryDomainInfoBasic,
  956. (PBYTE *) &pDomainInfo);
  957. if (ERROR_SUCCESS != dwErr)
  958. return szDomNameUnknown;
  959. switch (pDomainInfo->MachineRole)
  960. {
  961. case DsRole_RoleStandaloneWorkstation:
  962. case DsRole_RoleStandaloneServer:
  963. return szDomNameWorkgroup;
  964. break; // just in case
  965. }
  966. if (pDomainInfo->DomainNameFlat)
  967. return pDomainInfo->DomainNameFlat;
  968. else if (pDomainInfo->DomainNameDns)
  969. return pDomainInfo->DomainNameDns;
  970. else
  971. return szDomNameUnknown;
  972. }
  973. WCHAR wszIPAddress[128] = L"<error>";
  974. TCHAR *GetIPAddress ()
  975. {
  976. //get host address
  977. WORD wVersionRequested = MAKEWORD( 1, 1 );
  978. WSADATA wsaData;
  979. if (0 == WSAStartup(wVersionRequested,&wsaData))
  980. {
  981. char szHostName[256];
  982. if (0 == gethostname ( szHostName , 256 ))
  983. {
  984. hostent *h;
  985. if (NULL != (h=gethostbyname ( szHostName )))
  986. {
  987. in_addr *inaddr=(struct in_addr *)*h->h_addr_list;
  988. MultiByteToWideChar(CP_ACP,0,inet_ntoa(*inaddr),-1,wszIPAddress,128);
  989. }
  990. }
  991. }
  992. return wszIPAddress;
  993. }
  994. TCHAR *IsRDPNPinNetProviders ()
  995. {
  996. TCHAR NEWORK_PROVIDER_ORDER_KEY[] = _T("SYSTEM\\CurrentControlSet\\Control\\NetworkProvider\\Order");
  997. TCHAR PROVIDER_ORDER_VALUE[] = _T("ProviderOrder");
  998. TCHAR RDPNP_ENTRY[] = _T("RDPNP");
  999. BOOL bRdpNpExists = FALSE;
  1000. // read network privider key.
  1001. CRegistry regNetOrder;
  1002. LPTSTR szOldValue;
  1003. DWORD dwSize;
  1004. if ((ERROR_SUCCESS == regNetOrder.OpenKey(HKEY_LOCAL_MACHINE, NEWORK_PROVIDER_ORDER_KEY), KEY_READ) &&
  1005. (ERROR_SUCCESS == regNetOrder.ReadRegString(PROVIDER_ORDER_VALUE, &szOldValue, &dwSize)))
  1006. {
  1007. bRdpNpExists = (_tcsstr(szOldValue, RDPNP_ENTRY) != NULL);
  1008. }
  1009. if (TSEnabled () == bRdpNpExists)
  1010. {
  1011. return (_T("Passed"));
  1012. }
  1013. else
  1014. {
  1015. if (bRdpNpExists)
  1016. {
  1017. return _T("Error: RDPNP, exists in ProviderOrder, but TS is disabled!");
  1018. }
  1019. else
  1020. {
  1021. if (IsIt50TS())
  1022. {
  1023. // rdp np is only for 51+ so its ok if its missing for 50.
  1024. return _T("Passed");
  1025. }
  1026. else
  1027. {
  1028. return _T("ERROR, RDPNP is missing from ProviderOrder");
  1029. }
  1030. }
  1031. }
  1032. }
  1033. TCHAR *IsMultiConnectionAllowed ()
  1034. {
  1035. // SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","AllowMultipleTSSessions
  1036. CRegistry regWL;
  1037. DWORD dwAllowMultipal;
  1038. if ((ERROR_SUCCESS == regWL.OpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), KEY_READ)) &&
  1039. (ERROR_SUCCESS == regWL.ReadRegDWord(_T("AllowMultipleTSSessions"), &dwAllowMultipal)))
  1040. {
  1041. return dwAllowMultipal ? _T("Yes") : _T("No");
  1042. }
  1043. if (IsIt50TS())
  1044. {
  1045. return _T("Yes");
  1046. }
  1047. else
  1048. {
  1049. return _T("ERROR, registry missing");
  1050. }
  1051. }
  1052. TCHAR *LogonType ()
  1053. {
  1054. if (0 == _tcsicmp(GetDomName(), szDomNameWorkgroup))
  1055. {
  1056. CRegistry regWL;
  1057. DWORD dwLogonType;
  1058. if ((ERROR_SUCCESS == regWL.OpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), KEY_READ)) &&
  1059. (ERROR_SUCCESS == regWL.ReadRegDWord(_T("LogonType"), &dwLogonType)))
  1060. {
  1061. return dwLogonType == 0 ? _T("Classic Gina") : _T("New Fancy");
  1062. }
  1063. if (IsIt50TS())
  1064. {
  1065. return _T("Classic");
  1066. }
  1067. else
  1068. {
  1069. return _T("ERROR, registry missing");
  1070. }
  1071. }
  1072. else
  1073. {
  1074. return _T("Classic Gina");
  1075. }
  1076. }
  1077. BOOL IsTermSrvInSystemContext ()
  1078. {
  1079. USES_CONVERSION;
  1080. CRegistry reg;
  1081. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\TermService"), KEY_READ))
  1082. {
  1083. TCHAR *szObjectName;
  1084. DWORD dwSize;
  1085. if ( ERROR_SUCCESS == reg.ReadRegString( _T("ObjectName"), &szObjectName, &dwSize))
  1086. {
  1087. if (0 == _tcsicmp(szObjectName, _T("LocalSystem")))
  1088. {
  1089. return TRUE;
  1090. }
  1091. else
  1092. {
  1093. szMoreInfo << "ERROR:Termsrv is set to run using (" << T2A(szObjectName) << ") context." << endl;
  1094. }
  1095. }
  1096. else
  1097. {
  1098. szMoreInfo << "failed to read Objectname" << endl;
  1099. }
  1100. }
  1101. else
  1102. {
  1103. szMoreInfo << "failed to open termsrv registry" << endl;
  1104. }
  1105. return FALSE;
  1106. }
  1107. BOOL DontRun ()
  1108. {
  1109. szMoreInfo << "test not run because its not required." << endl;
  1110. return FALSE;
  1111. }
  1112. BOOL DoRun ()
  1113. {
  1114. szMoreInfo << "this test must be run." << endl;
  1115. return TRUE;
  1116. }
  1117. TCHAR *SystemDirectory()
  1118. {
  1119. TCHAR sysdir[MAX_PATH];
  1120. sysdir[0] = '\0';
  1121. if (GetSystemDirectory(sysdir, MAX_PATH) >= MAX_PATH) {
  1122. sysdir[MAX_PATH -1] = '\0';
  1123. }
  1124. _tcscpy(ReturnBuffer(), sysdir);
  1125. return ReturnBuffer();
  1126. }
  1127. int
  1128. #if !defined(_MIPS_) && !defined(_ALPHA_) && !defined(_PPC_)
  1129. _cdecl
  1130. #endif
  1131. main( int argc , char ** /* argv */)
  1132. {
  1133. typedef BOOL (PFN_BOOL)(void);
  1134. typedef TCHAR * (PFN_TestSubjective)(void);
  1135. USES_CONVERSION;
  1136. struct TVerificationTest
  1137. {
  1138. char szTestName[256]; // descriptive name of the test
  1139. PFN_BOOL *pfnNeedRunTest; // pointer to function that will be called to decide if the test need run, test is run if NULL.
  1140. PFN_TestSubjective *pfnSubTest; // pointer to function if the test returns TCHAR *
  1141. PFN_BOOL *pfnObjTest; // pointer to function if the test returns BOOL
  1142. }
  1143. theTests[] =
  1144. {
  1145. // {"DontRun...............................", DontRun, GetCompName, NULL},
  1146. // {"DoRun...............................", DoRun, GetCompName, NULL},
  1147. {"Machine Name...............................", NULL, GetCompName, NULL},
  1148. {"Domain Name................................", NULL, GetDomName, NULL},
  1149. {"IP Address.................................", NULL, GetIPAddress, NULL},
  1150. {"System Dir.................................", NULL, SystemDirectory, NULL},
  1151. {"ProductType................................", NULL, GetProductType, NULL},
  1152. {"ProductSuite...............................", NULL, GetProductSuite, NULL},
  1153. {"TS Version.................................", NULL, GetTSVersion, NULL},
  1154. {"Is this a server machine?..................", NULL, IsServer, NULL},
  1155. {"Is tsoc.log Present?.......................", NULL, NULL, IsTSOClogPresent},
  1156. {"Did TsOC get CompleteInstallationMessage...", NULL, NULL, DidTsOCgetCompleteInstallationMessage},
  1157. {"Is Clustering Services installed...........", NULL, IsClusteringInstalled, NULL},
  1158. {"Does ProductSuite Contain TS?..............", NULL, NULL, DoesProductSuiteContainTS},
  1159. {"Did OCM Install TSEnable...................", IsIt50TS, NULL, DidOCMInstallTSEnable},
  1160. {"Is TSEnabled registry alright?.............", NULL, NULL, TSEnabled},
  1161. {"Is Kernel TSEnabled?.......................", IsItServer, NULL, IsKernelTSEnable},
  1162. {"Is Terminal Server Registry Ok?............", NULL, NULL, IsTerminalServerRegistryOk},
  1163. {"GetWinstationList..........................", NULL, GetWinstationList, NULL},
  1164. {"Is TermServ Start Bit Ok?..................", NULL, IsTerminalServiceStartBitSet, NULL},
  1165. {"Is TermServ service running?...............", NULL, NULL, IsTerminalServiceRunning},
  1166. {"Is TermSrv in System Context?..............", NULL, NULL, IsTermSrvInSystemContext},
  1167. {"AreEffectiveConnectionAllowed..............", IsIt51TS, AreEffectiveConnectionAllowed, NULL },
  1168. {"Are Connections Allowed?...................", IsIt51TS, AreConnectionsAllowed, NULL},
  1169. {"Is RdpDr Installed Properly?...............", NULL, NULL, IsRdpDrInstalledProperly},
  1170. {"Is RdpNP in NetProviders?..................", IsIt51TS, IsRDPNPinNetProviders, NULL},
  1171. {"Are Multipal Connections Allowed...........", IsIt51TS, IsMultiConnectionAllowed, NULL},
  1172. {"Logon UI type..............................", IsIt51TS, LogonType, NULL},
  1173. {"Are Video keys setup right?................", NULL, NULL, CheckVideoKeys},
  1174. {"What mode is Terminal Server set in?.......", NULL, GetTSMode, NULL},
  1175. {"Is mode specific registry ok?..............", NULL, NULL, VerifyModeRegistry},
  1176. {"What is permission Mode set to?............", NULL, GetModePermissions, NULL},
  1177. {"Check termdd signature.....................", NULL, NULL, Check_termdd},
  1178. {"Check tdpipe signature.....................", NULL, NULL, Check_tdpipe},
  1179. {"Check tdtcp signature......................", NULL, NULL, Check_tdtcp},
  1180. {"Check rdpwd signature......................", NULL, NULL, Check_rdpwd},
  1181. {"Check rdpdd signature......................", NULL, NULL, Check_rdpdd},
  1182. {"Check rdpwsx signature.....................", NULL, NULL, Check_rdpwsx},
  1183. {"Is it 56 bit or 128?.......................", NULL, GetCypherStrenthOnRdpwd, NULL},
  1184. {"Is this a Beta System?.....................", NULL, IsBetaSystem, NULL},
  1185. {"Has Licence GracePeriod Expired............", NULL, IsLicenceGracePeriodOk, NULL},
  1186. {"Audio test.................................", IsIt51TS, NULL, IsAudioOk}
  1187. };
  1188. BOOL bEverythingOk = TRUE;
  1189. for (int i=0; i < sizeof(theTests)/sizeof(theTests[0]); i++)
  1190. {
  1191. ASSERT(theTests[i].pfnObjTest || theTests[i].pfnSubTest);
  1192. ASSERT(!(theTests[i].pfnObjTest && theTests[i].pfnSubTest));
  1193. if (theTests[i].pfnNeedRunTest && !(*(theTests[i].pfnNeedRunTest))())
  1194. {
  1195. // we asre asked to skip the test.
  1196. cout << theTests[i].szTestName << "Skipped Test" << endl;
  1197. }
  1198. else
  1199. {
  1200. if (theTests[i].pfnObjTest)
  1201. {
  1202. BOOL bResult = (*(theTests[i].pfnObjTest))();
  1203. cout << theTests[i].szTestName << (bResult ? "Passed" : "Failed") << endl;
  1204. if (!bResult)
  1205. bEverythingOk = FALSE;
  1206. }
  1207. else
  1208. {
  1209. char *szStr = T2A((*(theTests[i].pfnSubTest))());
  1210. if (szStr)
  1211. {
  1212. cout << theTests[i].szTestName << szStr << endl;
  1213. }
  1214. }
  1215. }
  1216. //
  1217. // if previous test had any details to tell us
  1218. //
  1219. if (szMoreInfo.pcount())
  1220. {
  1221. char *pStr = szMoreInfo.str();
  1222. cout << " Details:" << pStr;
  1223. cout << "------------------------------------------------" << endl;
  1224. bEverythingOk = FALSE;
  1225. ZeroMemory(pStr, 512);
  1226. szMoreInfo.seekp(ios::beg);
  1227. }
  1228. }
  1229. cout << endl;
  1230. if (argc == 1 ) // if some argumnent is provided skip these time consuming test.
  1231. {
  1232. cout << "Enumerating Licensing Servers (May take some time)...";
  1233. cout.flush();
  1234. if (EnumerateLicenseServers())
  1235. {
  1236. cout << ".....Passed, Found Some!" << endl;
  1237. }
  1238. else
  1239. {
  1240. cout << ".....Failed. No License Server Found." << endl;
  1241. }
  1242. cout << "Extracting Related Events from Event Log...";
  1243. cout.flush();
  1244. if (ExtractAllTSEvents())
  1245. {
  1246. cout << ".....Found Some. See if they give any clue." << endl;
  1247. }
  1248. else
  1249. {
  1250. cout << ".....Found None." << endl;
  1251. }
  1252. }
  1253. cout << endl;
  1254. if (bEverythingOk)
  1255. {
  1256. cout << endl;
  1257. cout << "**************************************************************" << endl;
  1258. cout << "*** Nothing wrong with TS could detected by this utility. ***" << endl;
  1259. cout << "*** If you think something is wrong contact the developer. ***" << endl;
  1260. cout << "**************************************************************" << endl;
  1261. return 0;
  1262. }
  1263. return 1;
  1264. }