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.

2789 lines
67 KiB

  1. // Copyright (c) 1998 - 1999 Microsoft Corporation
  2. #include "nt.h"
  3. #include "ntrtl.h"
  4. #include "nturtl.h"
  5. #include "stdafx.h"
  6. #include <dsrole.h>
  7. #include <wtsapi32.h>
  8. #include "winsta.h"
  9. #include "tstst.h"
  10. #include "testdata.h"
  11. #include <rdpsndp.h>
  12. #include <rdpstrm.h>
  13. //
  14. // global utilities and veraibles.
  15. //
  16. bool CheckifBinaryisSigned (TCHAR *szFile); // from tscert.cpp
  17. bool EnumerateLicenseServers (); // from timebomb.cpp
  18. bool HasLicenceGracePeriodExpired (); // from timebomb.cpp
  19. bool ExtractAllTSEvents();
  20. TCHAR *GetLicenseServers ();
  21. bool ValidateProductSuite (LPSTR SuiteName);
  22. bool IsTerminalServicesEnabled ( VOID );
  23. DWORD IsStringInMultiString(HKEY hkey, LPCTSTR szkey, LPCTSTR szvalue, LPCTSTR szCheckForString, bool *pbFound);
  24. bool DoesHydraKeysExists ();
  25. bool IsItRemoteMachine ();
  26. bool IsTermDDStartBitSet ();
  27. bool GetTSOCLogFileName (char *strFileName, UINT uiSize);
  28. bool FileExists (char *pszFullNameAndPath);
  29. bool IsRemoteAdminMode ();
  30. bool CheckModePermissions(DWORD *pdwSecurtyMode);
  31. bool IsFile128Bit(LPTSTR szFile, bool *pb128Bit);
  32. ULONG RDPDRINST_DetectInstall(); // defined in drdetect.cpp
  33. bool IsBetaSystem();
  34. bool CheckModeRegistry (bool bAppCompat, ostrstream &ResultStream);
  35. bool GetWinstationConfiguration (WINSTATIONCONFIG **ppInfo);
  36. bool CanPing (); // comes from ping.cpp
  37. const SERVER_INFO_101 *GetServerInfo()
  38. {
  39. ASSERT(IsItRemoteMachine());
  40. // for local machines, we will get GetMachineName() as null,
  41. if (CTSTestData::GetMachineName())
  42. {
  43. USES_CONVERSION;
  44. static SERVER_INFO_101 ServerInfo;
  45. LPBYTE Buffer;
  46. static bool bGotOnce = false;
  47. if (!bGotOnce)
  48. {
  49. TCHAR szMachineName[256];
  50. _tcscpy(szMachineName, CTSTestData::GetMachineName());
  51. if (NERR_Success == NetServerGetInfo(
  52. T2W(szMachineName),
  53. 102,
  54. &Buffer
  55. ))
  56. {
  57. bGotOnce = true;
  58. CopyMemory(&ServerInfo, Buffer, sizeof(SERVER_INFO_101));
  59. return &ServerInfo;
  60. }
  61. else
  62. {
  63. return NULL;
  64. }
  65. }
  66. else
  67. {
  68. return &ServerInfo;
  69. }
  70. }
  71. return NULL;
  72. }
  73. const OSVERSIONINFOEX *GetOSVersionInfo()
  74. {
  75. ASSERT(!IsItRemoteMachine());
  76. static OSVERSIONINFOEX gOsVersion;
  77. static bool bGotOnce = false;
  78. if (!bGotOnce)
  79. {
  80. ZeroMemory(&gOsVersion, sizeof(OSVERSIONINFOEX));
  81. gOsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  82. GetVersionEx( (LPOSVERSIONINFO ) &gOsVersion);
  83. bGotOnce = true;
  84. }
  85. return &gOsVersion;
  86. }
  87. // #include <strstream>
  88. #include "winsock2.h"
  89. // ostringstream sz
  90. #ifndef UNREFERENCED_PARAMETER
  91. #define UNREFERENCED_PARAMETER(P) (P)
  92. #endif
  93. #define OLD_VER_SET_CONDITION(_m_,_t_,_c_) _m_=(_m_|(_c_<<(1<<_t_)))
  94. TCHAR *aszStack[] = {
  95. // _T("noexport\%SystemRoot%\\system32\\drivers\\rdpwdd.sys"),
  96. _T("%SystemRoot%\\system32\\drivers\\termdd.sys"),
  97. _T("%SystemRoot%\\system32\\drivers\\tdasync.sys"),
  98. _T("%SystemRoot%\\system32\\drivers\\tdipx.sys"),
  99. _T("%SystemRoot%\\system32\\drivers\\tdnetb.sys"),
  100. _T("%SystemRoot%\\system32\\drivers\\tdpipe.sys"),
  101. _T("%SystemRoot%\\system32\\drivers\\tdspx.sys"),
  102. _T("%SystemRoot%\\system32\\drivers\\tdtcp.sys"),
  103. _T("%SystemRoot%\\system32\\drivers\\rdpwd.sys"),
  104. _T("%SystemRoot%\\system32\\rdpdd.dll"),
  105. _T("%SystemRoot%\\system32\\rdpwsx.dll")
  106. };
  107. TCHAR *GetTSVersion()
  108. {
  109. static TCHAR Version[256] = TEXT("");
  110. if (_tcslen(Version) != 0)
  111. return Version;
  112. CRegistry oRegTermsrv;
  113. DWORD cbVersion = 0;
  114. LPTSTR szVersion = NULL;
  115. if ((ERROR_SUCCESS == oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ, CTSTestData::GetMachineName())) &&
  116. (ERROR_SUCCESS == oRegTermsrv.ReadRegString(_T("ProductVersion"), &szVersion, &cbVersion)))
  117. {
  118. _tcscpy(Version, szVersion);
  119. return Version;
  120. }
  121. return _T("Error finding Version.");
  122. }
  123. EResult GetTSVersion (ostrstream &ResultStream)
  124. {
  125. USES_CONVERSION;
  126. ResultStream << T2A(GetTSVersion());
  127. return ePassed;
  128. }
  129. bool IsIt50TS()
  130. {
  131. return (0 == _tcsicmp(GetTSVersion(), _T("5.0")));
  132. }
  133. bool IsIt51TS()
  134. {
  135. return (0 == _tcsicmp(GetTSVersion(), _T("5.1")));
  136. }
  137. bool DoIhaveRPCPermissions ()
  138. {
  139. HANDLE hServer = WTS_CURRENT_SERVER_HANDLE;
  140. if (CTSTestData::GetMachineName())
  141. {
  142. TCHAR szMachineName[256];
  143. _tcscpy(szMachineName, CTSTestData::GetMachineName());
  144. hServer = WTSOpenServer (szMachineName);
  145. }
  146. LPTSTR buffer;
  147. DWORD dwBytesReturned;
  148. if (WTSQuerySessionInformation(
  149. hServer,
  150. 65536,
  151. WTSInitialProgram,
  152. &buffer,
  153. &dwBytesReturned))
  154. {
  155. WTSFreeMemory(buffer);
  156. return true;
  157. }
  158. if (CTSTestData::GetMachineName())
  159. WTSCloseServer(hServer);
  160. return false;
  161. }
  162. bool DoIHaveEnufPermissions ()
  163. {
  164. char szOutput[512];
  165. ostrstream oTestResult(szOutput, 512);
  166. ZeroMemory(oTestResult.str(), 512);
  167. //if (!DoIhaveRPCPermissions())
  168. //{
  169. // return false;
  170. //}
  171. CRegistry oRegTermsrv;
  172. return ERROR_SUCCESS == oRegTermsrv.OpenKey(
  173. HKEY_LOCAL_MACHINE,
  174. _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"),
  175. KEY_READ,
  176. CTSTestData::GetMachineName()
  177. );
  178. }
  179. bool IsUserRemoteAdmin ()
  180. {
  181. if (IsItRemoteMachine())
  182. {
  183. USES_CONVERSION;
  184. TCHAR strNTFilename[256];
  185. if (CTSTestData::GetMachineNamePath())
  186. {
  187. _tcscpy(strNTFilename, CTSTestData::GetMachineNamePath());
  188. _tcscat(strNTFilename, _T("\\admin$\\system32\\ntoskrnl.exe"));
  189. }
  190. HANDLE hFile = CreateFile(strNTFilename, 0, FILE_SHARE_READ,
  191. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  192. if (hFile != INVALID_HANDLE_VALUE)
  193. {
  194. CloseHandle(hFile);
  195. return true;
  196. }
  197. return false;
  198. }
  199. else
  200. {
  201. // we dont require admin priviledges if running on local machine
  202. return true;
  203. }
  204. }
  205. EResult HasLicenceGracePeriodExpired (ostrstream &ResultStream)
  206. {
  207. if (HasLicenceGracePeriodExpired())
  208. {
  209. ResultStream << "Its expired";
  210. return eFailed;
  211. }
  212. else
  213. {
  214. ResultStream << "No, its not expired.";
  215. return ePassed;
  216. }
  217. }
  218. EResult Check_StackBinSigatures (ostrstream &ResultStream)
  219. {
  220. USES_CONVERSION;
  221. bool bRet = true;
  222. LPTSTR aStackBins[] =
  223. {
  224. _T("%SystemRoot%\\system32\\drivers\\termdd.sys"),
  225. _T("%SystemRoot%\\system32\\drivers\\tdpipe.sys"),
  226. _T("%SystemRoot%\\system32\\drivers\\tdtcp.sys"),
  227. _T("%SystemRoot%\\system32\\drivers\\rdpwd.sys"),
  228. _T("%SystemRoot%\\system32\\rdpdd.dll"),
  229. _T("%SystemRoot%\\system32\\rdpwsx.dll")
  230. };
  231. for (int i = 0; i < sizeof(aStackBins)/sizeof(aStackBins[0]); i++)
  232. {
  233. if (!CheckifBinaryisSigned(aStackBins[i]))
  234. {
  235. ResultStream << "Invalid Signature for:" << T2A(aStackBins[i]) << ",";
  236. bRet = false;
  237. }
  238. }
  239. if (bRet)
  240. {
  241. ResultStream << "Passed";
  242. return ePassed;
  243. }
  244. else
  245. {
  246. return eFailed;
  247. }
  248. }
  249. EResult IsRdpDrInstalledProperly (ostrstream &ResultStream)
  250. {
  251. //
  252. // we cannot do this test for remote machine.
  253. //
  254. ASSERT(IsItLocalMachine());
  255. if (RDPDRINST_DetectInstall())
  256. {
  257. ResultStream << "Passed";
  258. return ePassed;
  259. }
  260. else
  261. {
  262. ResultStream << "Failed";
  263. return eFailed;
  264. }
  265. }
  266. EResult GetModePermissions (ostrstream &ResultStream)
  267. {
  268. CRegistry reg;
  269. DWORD dwSecurityMode;
  270. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ, CTSTestData::GetMachineName()))
  271. {
  272. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("TSUserEnabled"), &dwSecurityMode))
  273. {
  274. if (dwSecurityMode == 0)
  275. {
  276. ResultStream << "Its W2k Compatible";
  277. return ePassed;
  278. }
  279. else if (dwSecurityMode == 1)
  280. {
  281. ResultStream << "Its TS4 Compatible";
  282. return ePassed;
  283. }
  284. else
  285. {
  286. ResultStream << "SYSTEM\\CurrentControlSet\\Control\\Terminal Server/TSUserEnabled has wrong value" << dwSecurityMode << "!";
  287. return eFailedToExecute;
  288. }
  289. }
  290. else
  291. {
  292. ResultStream << "failed to read TSUserEnabled";
  293. return eFailedToExecute;
  294. }
  295. }
  296. else
  297. {
  298. ResultStream << "failed to read SYSTEM\\CurrentControlSet\\Control\\Terminal Server";
  299. return eFailedToExecute;
  300. }
  301. }
  302. bool CheckModePermissions (DWORD *pdwSecurtyMode)
  303. {
  304. // PERM_WIN2K = 0,
  305. // PERM_TS4 = 1
  306. CRegistry reg;
  307. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ, CTSTestData::GetMachineName()))
  308. {
  309. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("TSUserEnabled"), pdwSecurtyMode))
  310. {
  311. return (*pdwSecurtyMode== 0) || (*pdwSecurtyMode== 1);
  312. }
  313. }
  314. return false;
  315. }
  316. EResult GetCypherStrenthOnRdpwd (ostrstream &ResultStream)
  317. {
  318. bool bFile128bit;
  319. TCHAR strFileName[256];
  320. if (CTSTestData::GetMachineName())
  321. {
  322. _tcscpy(strFileName, CTSTestData::GetMachineNamePath());
  323. _tcscat(strFileName, _T("\\admin$\\system32\\drivers\\rdpwd.sys"));
  324. }
  325. else
  326. {
  327. _tcscpy(strFileName, _T("%SystemRoot%\\system32\\drivers\\rdpwd.sys"));
  328. }
  329. if ( IsFile128Bit(strFileName, &bFile128bit) )
  330. {
  331. ResultStream << (bFile128bit ? "128 Bit" : "56 Bit");
  332. return ePassed;
  333. }
  334. else
  335. {
  336. ResultStream << "Failed to get cypher strength on rdpwd.sys, You may not have sufficient permissions.";
  337. return eFailedToExecute;
  338. }
  339. }
  340. bool IsFile128Bit(LPTSTR szFile, bool *pb128Bit)
  341. {
  342. USES_CONVERSION;
  343. DWORD dwHandle;
  344. TCHAR szFullFile[MAX_PATH +1];
  345. bool bSuccess = false;
  346. if (ExpandEnvironmentStrings(szFile, szFullFile, MAX_PATH))
  347. {
  348. if (FileExists(T2A(szFullFile)))
  349. {
  350. DWORD dwSize = GetFileVersionInfoSize(szFullFile, &dwHandle);
  351. if (dwSize > 0)
  352. {
  353. BYTE *pbData = new BYTE[dwSize];
  354. if (pbData)
  355. {
  356. if (GetFileVersionInfo(szFullFile, 0, dwSize, pbData))
  357. {
  358. TCHAR *szFileDescription;
  359. UINT uiLen = 0;
  360. if (VerQueryValue(pbData, _T("\\StringFileInfo\\040904B0\\FileDescription"), (LPVOID *)&szFileDescription, &uiLen))
  361. {
  362. if (_tcsstr(szFileDescription, _T("Not for Export")))
  363. {
  364. *pb128Bit = true;
  365. bSuccess = true;
  366. }
  367. else if (_tcsstr(szFileDescription, _T("Export Version")))
  368. {
  369. *pb128Bit = false;
  370. bSuccess = true;
  371. }
  372. }
  373. }
  374. delete [] pbData;
  375. }
  376. }
  377. }
  378. }
  379. return bSuccess;
  380. }
  381. bool ValidateProductSuite (LPSTR SuiteName)
  382. {
  383. bool rVal = false;
  384. LONG Rslt;
  385. HKEY hKey = NULL;
  386. DWORD Type = 0;
  387. DWORD Size = 0;
  388. LPSTR ProductSuite = NULL;
  389. LPSTR p;
  390. Rslt = RegOpenKeyA(
  391. HKEY_LOCAL_MACHINE,
  392. "System\\CurrentControlSet\\Control\\ProductOptions",
  393. &hKey
  394. );
  395. if (Rslt != ERROR_SUCCESS)
  396. goto exit;
  397. Rslt = RegQueryValueExA( hKey, "ProductSuite", NULL, &Type, NULL, &Size );
  398. if (Rslt != ERROR_SUCCESS || !Size)
  399. goto exit;
  400. ProductSuite = (LPSTR) LocalAlloc( LPTR, Size );
  401. if (!ProductSuite)
  402. goto exit;
  403. Rslt = RegQueryValueExA( hKey, "ProductSuite", NULL, &Type,
  404. (LPBYTE) ProductSuite, &Size );
  405. if (Rslt != ERROR_SUCCESS || Type != REG_MULTI_SZ)
  406. goto exit;
  407. p = ProductSuite;
  408. while (*p)
  409. {
  410. if (lstrcmpA( p, SuiteName ) == 0)
  411. {
  412. rVal = true;
  413. break;
  414. }
  415. p += (lstrlenA( p ) + 1);
  416. }
  417. exit:
  418. if (ProductSuite)
  419. LocalFree( ProductSuite );
  420. if (hKey)
  421. RegCloseKey( hKey );
  422. return rVal;
  423. }
  424. bool IsTerminalServicesEnabled( VOID )
  425. {
  426. bool bResult = false;
  427. DWORD dwVersion;
  428. OSVERSIONINFOEXA osVersionInfo;
  429. DWORDLONG dwlConditionMask = 0;
  430. HMODULE hmodK32 = NULL;
  431. typedef ULONGLONG (*PFnVerSetConditionMask) ( ULONGLONG, ULONG, UCHAR );
  432. typedef BOOL (*PFnVerifyVersionInfoA) (POSVERSIONINFOEXA, DWORD, DWORDLONG);
  433. PFnVerSetConditionMask pfnVerSetConditionMask;
  434. PFnVerifyVersionInfoA pfnVerifyVersionInfoA;
  435. dwVersion = GetVersion();
  436. /* are we running NT ? */
  437. if (!(dwVersion & 0x80000000))
  438. {
  439. // Is it NT 50 or greater ?
  440. if (LOBYTE(LOWORD(dwVersion)) > 4)
  441. {
  442. /* In NT5 we need to use the Product Suite APIs
  443. Don't static link because it won't load on non-NT5 systems */
  444. hmodK32 = GetModuleHandleA( "KERNEL32.DLL" );
  445. if (hmodK32)
  446. {
  447. pfnVerSetConditionMask = (PFnVerSetConditionMask )GetProcAddress( hmodK32, "VerSetConditionMask");
  448. if (pfnVerSetConditionMask)
  449. {
  450. /* get the condition mask. */
  451. dwlConditionMask = (*pfnVerSetConditionMask)(dwlConditionMask, VER_SUITENAME, VER_AND);
  452. pfnVerifyVersionInfoA = (PFnVerifyVersionInfoA)GetProcAddress( hmodK32, "VerifyVersionInfoA") ;
  453. if (pfnVerifyVersionInfoA != NULL)
  454. {
  455. ZeroMemory(&osVersionInfo, sizeof(osVersionInfo));
  456. osVersionInfo.dwOSVersionInfoSize = sizeof(osVersionInfo);
  457. osVersionInfo.wSuiteMask = VER_SUITE_TERMINAL;
  458. bResult = (*pfnVerifyVersionInfoA)(
  459. &osVersionInfo,
  460. VER_SUITENAME,
  461. dwlConditionMask) != 0;
  462. }
  463. }
  464. }
  465. }
  466. else
  467. {
  468. /* This is NT 40 */
  469. bResult = ValidateProductSuite( "Terminal Server" );
  470. }
  471. }
  472. return bResult;
  473. }
  474. /*--------------------------------------------------------------------------------------------------------
  475. * DWORD IsStringInMultiString(HKEY hkey, LPCTSTR szkey, LPCTSTR szvalue, LPCTSTR szCheckForString, bool *pbFound)
  476. * checks if parameter string exists in given multistring.
  477. * returns error code.
  478. * -------------------------------------------------------------------------------------------------------*/
  479. DWORD IsStringInMultiString(HKEY hkey, LPCTSTR szkey, LPCTSTR szvalue, LPCTSTR szCheckForString, bool *pbFound)
  480. {
  481. ASSERT(szkey && *szkey);
  482. ASSERT(szvalue && *szvalue);
  483. ASSERT(szCheckForString&& *szCheckForString);
  484. ASSERT(*szkey != '\\');
  485. ASSERT(pbFound);
  486. // not yet found.
  487. *pbFound = false;
  488. CRegistry reg;
  489. DWORD dwError = reg.OpenKey(hkey, szkey, KEY_READ, CTSTestData::GetMachineName()); // open up the required key.
  490. if (dwError == NO_ERROR)
  491. {
  492. LPTSTR szSuiteValue;
  493. DWORD dwSize;
  494. dwError = reg.ReadRegMultiString(szvalue, &szSuiteValue, &dwSize);
  495. if (dwError == NO_ERROR)
  496. {
  497. LPCTSTR pTemp = szSuiteValue;
  498. while(_tcslen(pTemp) > 0 )
  499. {
  500. if (_tcscmp(pTemp, szCheckForString) == 0)
  501. {
  502. *pbFound = true;
  503. break;
  504. }
  505. pTemp += _tcslen(pTemp) + 1; // point to the next string within the multistring.
  506. if ( DWORD(pTemp - szSuiteValue) > (dwSize / sizeof(TCHAR)))
  507. break; // temporary pointer passes the size of the szSuiteValue something is wrong with szSuiteValue.
  508. }
  509. }
  510. }
  511. return dwError;
  512. }
  513. bool DoesHydraKeysExists()
  514. {
  515. bool bStringExists = false;
  516. DWORD dw = IsStringInMultiString(
  517. HKEY_LOCAL_MACHINE,
  518. _T("SYSTEM\\CurrentControlSet\\Control\\ProductOptions"),
  519. _T("ProductSuite"),
  520. _T("Terminal Server"),
  521. &bStringExists);
  522. return (dw == ERROR_SUCCESS) && bStringExists;
  523. }
  524. /*
  525. TCHAR *IsItAppServer ()
  526. {
  527. return ((GetOSVersionInfo()->wSuiteMask & VER_SUITE_TERMINAL) &&
  528. !(GetOSVersionInfo()->wSuiteMask & VER_SUITE_SINGLEUSERTS)) ? _T("Yes") : _T("No");
  529. }
  530. */
  531. bool IsItPTS( VOID )
  532. {
  533. return ( 0 != (GetOSVersionInfo()->wSuiteMask & VER_SUITE_SINGLEUSERTS));
  534. }
  535. bool IsItRemoteMachine ()
  536. {
  537. return CTSTestData::GetMachineName() != NULL;
  538. }
  539. bool AreWeInsideSession ()
  540. {
  541. return GetSystemMetrics(SM_REMOTESESSION) != 0;
  542. }
  543. bool IsItLocalMachine ()
  544. {
  545. return !IsItRemoteMachine ();
  546. }
  547. bool IsItLocalServer ()
  548. {
  549. return IsItServer () && IsItLocalMachine ();
  550. }
  551. bool IsItServer ()
  552. {
  553. if (IsItRemoteMachine())
  554. {
  555. const SERVER_INFO_101 *pServerInfo;
  556. pServerInfo = GetServerInfo();
  557. if (pServerInfo)
  558. {
  559. return ( (pServerInfo->sv101_type & SV_TYPE_DOMAIN_CTRL) ||
  560. (pServerInfo->sv101_type & SV_TYPE_DOMAIN_BAKCTRL) ||
  561. (pServerInfo->sv101_type & SV_TYPE_SERVER_NT));
  562. }
  563. else
  564. {
  565. return true; // we could not determine if its server or not, Lets say its server.
  566. }
  567. }
  568. else
  569. {
  570. return GetOSVersionInfo()->wProductType != VER_NT_WORKSTATION;
  571. }
  572. }
  573. bool IsAudioEnabled()
  574. {
  575. USES_CONVERSION;
  576. WINSTATIONCONFIG *pWSInfo = NULL;
  577. if ( !AreWeInsideSession() )
  578. return FALSE;
  579. if (GetWinstationConfiguration(&pWSInfo))
  580. {
  581. return !(pWSInfo->User.fDisableCam);
  582. }
  583. return FALSE;
  584. }
  585. bool IsItRemoteConsole( VOID )
  586. {
  587. return ( AreWeInsideSession() && (NtCurrentPeb()->SessionId == 0 || IsItPTS()) );
  588. }
  589. EResult IsItServer (ostrstream &ResultStream)
  590. {
  591. ResultStream << (IsItServer ()) ? "Its a workstation" : "Its a server";
  592. return (IsItServer()) ? ePassed : eFailed;
  593. }
  594. EResult GetProductType (ostrstream &ResultStream)
  595. {
  596. ASSERT(IsItLocalMachine());
  597. BYTE wProductType = GetOSVersionInfo()->wProductType;
  598. if (wProductType == VER_NT_WORKSTATION)
  599. {
  600. ResultStream << "VER_NT_WORKSTATION";
  601. }
  602. if (wProductType == VER_NT_DOMAIN_CONTROLLER)
  603. {
  604. ResultStream << "VER_NT_DOMAIN_CONTROLLER ";
  605. }
  606. if (wProductType == VER_NT_SERVER)
  607. {
  608. ResultStream << "VER_NT_SERVER ";
  609. }
  610. return ePassed;
  611. }
  612. EResult GetProductSuite (ostrstream &ResultStream)
  613. {
  614. ASSERT(IsItLocalMachine());
  615. WORD wProductSuite = GetOSVersionInfo()->wSuiteMask;
  616. if (wProductSuite & VER_SERVER_NT)
  617. {
  618. ResultStream << "VER_SERVER_NT ";
  619. }
  620. if (wProductSuite & VER_WORKSTATION_NT)
  621. {
  622. ResultStream << "VER_WORKSTATION_NT ";
  623. }
  624. if (wProductSuite & VER_SUITE_SMALLBUSINESS)
  625. {
  626. ResultStream << "VER_SUITE_SMALLBUSINESS ";
  627. }
  628. if (wProductSuite & VER_SUITE_ENTERPRISE)
  629. {
  630. ResultStream << "VER_SUITE_ENTERPRISE ";
  631. }
  632. if (wProductSuite & VER_SUITE_BACKOFFICE)
  633. {
  634. ResultStream << "VER_SUITE_BACKOFFICE ";
  635. }
  636. if (wProductSuite & VER_SUITE_COMMUNICATIONS)
  637. {
  638. ResultStream << "VER_SUITE_COMMUNICATIONS ";
  639. }
  640. if (wProductSuite & VER_SUITE_TERMINAL)
  641. {
  642. ResultStream << "VER_SUITE_TERMINAL ";
  643. }
  644. if (wProductSuite & VER_SUITE_SMALLBUSINESS_RESTRICTED)
  645. {
  646. ResultStream << "VER_SUITE_SMALLBUSINESS_RESTRICTED ";
  647. }
  648. if (wProductSuite & VER_SUITE_EMBEDDEDNT)
  649. {
  650. ResultStream << "VER_SUITE_EMBEDDEDNT ";
  651. }
  652. if (wProductSuite & VER_SUITE_DATACENTER)
  653. {
  654. ResultStream << "VER_SUITE_DATACENTER ";
  655. }
  656. if (wProductSuite & VER_SUITE_SINGLEUSERTS)
  657. {
  658. ResultStream << "VER_SUITE_SINGLEUSERTS ";
  659. }
  660. if (wProductSuite & VER_SUITE_PERSONAL)
  661. {
  662. ResultStream << "VER_SUITE_PERSONAL ";
  663. }
  664. return ePassed;
  665. }
  666. /*
  667. TCHAR *IsServer ()
  668. {
  669. return IsItServer() ? _T("Its a Server") : _T("Its a WorkStation");
  670. }
  671. */
  672. EResult IsKernelTSEnable (ostrstream &ResultStream)
  673. {
  674. ASSERT(IsItLocalMachine());
  675. if (IsTerminalServicesEnabled())
  676. {
  677. ResultStream << "Yes.";
  678. return ePassed;
  679. }
  680. else
  681. {
  682. ResultStream << "No.";
  683. return eFailed;
  684. }
  685. }
  686. bool TSEnabled ()
  687. {
  688. CRegistry reg;
  689. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ, CTSTestData::GetMachineName()))
  690. {
  691. DWORD dwTSEnabled = 0;
  692. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("TSEnabled"), &dwTSEnabled))
  693. {
  694. return dwTSEnabled == 1;
  695. }
  696. }
  697. return false;
  698. }
  699. EResult TSEnabled (ostrstream &ResultStream)
  700. {
  701. if (TSEnabled())
  702. {
  703. ResultStream << "Yes.";
  704. return ePassed;
  705. }
  706. else
  707. {
  708. ResultStream << "No.";
  709. return eFailed;
  710. }
  711. }
  712. EResult DoesProductSuiteContainTS (ostrstream &ResultStream)
  713. {
  714. if (DoesHydraKeysExists())
  715. {
  716. ResultStream << "Yes.";
  717. return ePassed;
  718. }
  719. else
  720. {
  721. ResultStream << "No.";
  722. return eFailed;
  723. }
  724. }
  725. EResult IsTerminalServerRegistryOk (ostrstream &ResultStream)
  726. {
  727. CRegistry reg1;
  728. CRegistry reg2;
  729. CRegistry reg3;
  730. if (
  731. (ERROR_SUCCESS == reg1.OpenKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ, CTSTestData::GetMachineName())) &&
  732. (ERROR_SUCCESS == reg2.OpenKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\WinStations"), KEY_READ, CTSTestData::GetMachineName())) &&
  733. (ERROR_SUCCESS == reg3.OpenKey(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\Terminal Server"), KEY_READ, CTSTestData::GetMachineName())))
  734. {
  735. ResultStream << "Yes.";
  736. return ePassed;
  737. }
  738. else
  739. {
  740. ResultStream << "No.";
  741. return eFailed;
  742. }
  743. }
  744. EResult GetWinstationList (ostrstream &ResultStream)
  745. {
  746. USES_CONVERSION;
  747. CRegistry reg2;
  748. bool bFoundNonConsoleWinstation = false;
  749. if (ERROR_SUCCESS == reg2.OpenKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\WinStations"), KEY_READ, CTSTestData::GetMachineName()))
  750. {
  751. LPTSTR szWinstation;
  752. DWORD dwSize;
  753. bool bFirst = true;
  754. if (ERROR_SUCCESS == reg2.GetFirstSubKey(&szWinstation, &dwSize))
  755. {
  756. do
  757. {
  758. if (0 != _tcsicmp(szWinstation, _T("Console")))
  759. {
  760. bFoundNonConsoleWinstation = true;
  761. }
  762. if (!bFirst)
  763. {
  764. ResultStream << ", ";
  765. }
  766. ResultStream << T2A(szWinstation);
  767. bFirst = false;
  768. }
  769. while (ERROR_SUCCESS == reg2.GetNextSubKey(&szWinstation, &dwSize));
  770. }
  771. }
  772. else
  773. {
  774. ResultStream << "Failed to open winstations registry";
  775. return eFailed;
  776. }
  777. if (!bFoundNonConsoleWinstation)
  778. {
  779. // ResultStream << "Error, Only Console Winstation found";
  780. return eFailed;
  781. }
  782. else
  783. {
  784. return ePassed;
  785. }
  786. }
  787. EResult IsTerminalServiceStartBitSet (ostrstream &ResultStream)
  788. {
  789. CRegistry reg;
  790. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\TermService"), KEY_READ, CTSTestData::GetMachineName()))
  791. {
  792. DWORD dwTermServStartBit = 0;
  793. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("Start"), &dwTermServStartBit))
  794. {
  795. switch (dwTermServStartBit)
  796. {
  797. case 2:
  798. ResultStream << "AutoStart";
  799. break;
  800. case 3:
  801. ResultStream << "Manual Start";
  802. break;
  803. case 4:
  804. ResultStream << "Error, Disabled";
  805. break;
  806. default:
  807. ResultStream << "ERROR:Wrong value for startbit";
  808. }
  809. if (IsIt50TS())
  810. {
  811. if (2 == dwTermServStartBit)
  812. return ePassed;
  813. else
  814. return eFailed;
  815. }
  816. else
  817. {
  818. if (IsIt51TS())
  819. {
  820. if (3 == dwTermServStartBit)
  821. return ePassed;
  822. else
  823. return eFailed;
  824. }
  825. ResultStream << "what version of its is it ?";
  826. return eFailedToExecute;
  827. }
  828. }
  829. else
  830. {
  831. ResultStream << "Failed to read startbit";
  832. return eFailedToExecute;
  833. }
  834. }
  835. else
  836. {
  837. ResultStream << "Failed to read startbit";
  838. return eFailedToExecute;
  839. }
  840. }
  841. bool IsTermDDStartBitSet ()
  842. {
  843. CRegistry reg;
  844. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\TermDD"), KEY_READ, CTSTestData::GetMachineName()))
  845. {
  846. DWORD dwTermDDStartBit = 0;
  847. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("Start"), &dwTermDDStartBit))
  848. {
  849. return dwTermDDStartBit == 2;
  850. }
  851. }
  852. return false;
  853. }
  854. EResult IsGroupPolicyOk (ostrstream &ResultStream)
  855. {
  856. CRegistry reg;
  857. if (ERROR_SUCCESS == reg.OpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services"), KEY_READ, CTSTestData::GetMachineName()))
  858. {
  859. DWORD dwDenyConnections;
  860. if (ERROR_SUCCESS == reg.ReadRegDWord(_T("fDenyTSConnections"), &dwDenyConnections))
  861. {
  862. if (dwDenyConnections == 0)
  863. {
  864. ResultStream << "Passed";
  865. return ePassed;
  866. }
  867. else
  868. {
  869. ResultStream << "Group Policy does not allow connections";
  870. return eFailed;
  871. }
  872. }
  873. }
  874. ResultStream << "Passed,Policy does not exist";
  875. return ePassed;
  876. }
  877. /*
  878. bool AreEffectiveConnectionAllowed ()
  879. {
  880. HMODULE hmodRegAPI = LoadLibrary( _T("RegApi.dll") );
  881. if (hmodRegAPI)
  882. {
  883. typedef BOOLEAN (*PFDenyConnectionPolicy) ();
  884. PFDenyConnectionPolicy pfnDenyConnectionPolicy;
  885. pfnDenyConnectionPolicy = (PFDenyConnectionPolicy) GetProcAddress( hmodRegAPI, "RegDenyTSConnectionsPolicy");
  886. if (pfnDenyConnectionPolicy)
  887. {
  888. return (*pfnDenyConnectionPolicy)() ? false : true;
  889. }
  890. else
  891. {
  892. szMoreInfo << "Failed to get proc RegDenyTSConnectionsPolicy" << endl;
  893. return false;
  894. }
  895. }
  896. else
  897. {
  898. szMoreInfo << "Failed to Load regapi.dll" << endl;
  899. return false;
  900. }
  901. }
  902. */
  903. EResult AreConnectionsAllowed(ostrstream &ResultStream)
  904. {
  905. DWORD dwError;
  906. CRegistry oRegTermsrv;
  907. dwError = oRegTermsrv.OpenKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ, CTSTestData::GetMachineName());
  908. if (ERROR_SUCCESS == dwError)
  909. {
  910. DWORD dwDenyConnect;
  911. dwError = oRegTermsrv.ReadRegDWord(_T("fDenyTSConnections"), &dwDenyConnect);
  912. if (ERROR_SUCCESS == dwError)
  913. {
  914. if (dwDenyConnect == 1)
  915. {
  916. ResultStream << "Failed, Connections are denied";
  917. return eFailed;
  918. }
  919. else
  920. {
  921. ResultStream << "Passed, Connections are allowed";
  922. return ePassed;
  923. }
  924. }
  925. else
  926. {
  927. ResultStream << "failed to read value";
  928. return eFailedToExecute;
  929. }
  930. }
  931. else
  932. {
  933. ResultStream << "failed to open key";
  934. return eFailedToExecute;
  935. }
  936. }
  937. bool GetTSOCLogFileName(char *strFileName, UINT uiSize)
  938. {
  939. USES_CONVERSION;
  940. if (CTSTestData::GetMachineName())
  941. {
  942. strcpy(strFileName, T2A(CTSTestData::GetMachineNamePath()));
  943. strcat(strFileName, "\\admin$");
  944. }
  945. else
  946. {
  947. if (!GetSystemWindowsDirectoryA(strFileName, uiSize))
  948. return false;
  949. }
  950. strcat(strFileName, "\\tsoc.log");
  951. ASSERT(strlen(strFileName) < uiSize);
  952. return true;
  953. }
  954. char *IncompleteMessage = "Error:TSOC Did not get OC_COMPLETE_INSTALLATION.";
  955. EResult DidTsOCgetCompleteInstallationMessage (ostrstream &ResultStream)
  956. {
  957. if (!IsTSOClogPresent())
  958. {
  959. ResultStream << "Failed because tsoc.log does not exist." << endl;
  960. return eFailedToExecute;
  961. }
  962. char strTSOCLog[256];
  963. GetTSOCLogFileName(strTSOCLog, 256);
  964. ifstream ifSrc(strTSOCLog);
  965. if(!ifSrc)
  966. {
  967. ResultStream << "Failed to open tsoc.log file." << endl;
  968. return eFailedToExecute;
  969. }
  970. char tempSrc[256];
  971. while(!ifSrc.eof())
  972. {
  973. ifSrc.getline(tempSrc, 256);
  974. if (strstr(tempSrc, IncompleteMessage))
  975. {
  976. ResultStream << "Failed";
  977. return eFailed;
  978. }
  979. }
  980. ResultStream << "Passed";
  981. return ePassed;
  982. }
  983. bool FileExists(char *pszFullNameAndPath)
  984. {
  985. ASSERT(pszFullNameAndPath);
  986. if (pszFullNameAndPath && pszFullNameAndPath[0])
  987. {
  988. HANDLE hFile = CreateFileA(pszFullNameAndPath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
  989. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  990. if (hFile != INVALID_HANDLE_VALUE)
  991. {
  992. CloseHandle(hFile);
  993. return true;
  994. }
  995. }
  996. return false;
  997. }
  998. bool IsTSOClogPresent ()
  999. {
  1000. char strTSOCLog[256];
  1001. GetTSOCLogFileName(strTSOCLog, 256);
  1002. return FileExists(strTSOCLog);
  1003. }
  1004. EResult IsTSOClogPresent (ostrstream &ResultStream)
  1005. {
  1006. if (IsTSOClogPresent ())
  1007. {
  1008. ResultStream << "Passed";
  1009. return ePassed;
  1010. }
  1011. else
  1012. {
  1013. ResultStream << "Failed";
  1014. return eFailed;
  1015. }
  1016. }
  1017. EResult DidOCMInstallTSEnable(ostrstream &ResultStream)
  1018. {
  1019. CRegistry reg;
  1020. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\OC Manager\\SubComponents"), KEY_READ, CTSTestData::GetMachineName()))
  1021. {
  1022. DWORD dwTSEnabled = 0;
  1023. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("tsenable"), &dwTSEnabled))
  1024. {
  1025. if (dwTSEnabled == 1)
  1026. {
  1027. ResultStream << "Passed";
  1028. return ePassed;
  1029. }
  1030. else
  1031. {
  1032. ResultStream << "Failed";
  1033. return eFailed;
  1034. }
  1035. }
  1036. else
  1037. {
  1038. ResultStream << "Failed to open Value";
  1039. return eFailed;
  1040. }
  1041. }
  1042. else
  1043. {
  1044. ResultStream << "Failed to open key";
  1045. return eFailedToExecute;
  1046. }
  1047. }
  1048. EResult IsClusteringInstalled (ostrstream &ResultStream)
  1049. {
  1050. DWORD dwClusterState;
  1051. if (ERROR_SUCCESS == GetNodeClusterState(NULL, &dwClusterState))
  1052. {
  1053. if (dwClusterState != ClusterStateNotInstalled)
  1054. {
  1055. ResultStream << "***Failed. Clustering is installed.";
  1056. return eFailed;
  1057. }
  1058. }
  1059. ResultStream << "Passed.";
  1060. return ePassed;
  1061. }
  1062. EResult GetTSMode (ostrstream &ResultStream)
  1063. {
  1064. if (!IsItServer() && !IsRemoteAdminMode())
  1065. {
  1066. ResultStream << "ERROR:The machine is in app server Mode for Professional";
  1067. return eFailed;
  1068. }
  1069. else
  1070. {
  1071. ResultStream << (IsRemoteAdminMode() ? "Remote Admin" : "Application Server");
  1072. return ePassed;
  1073. }
  1074. }
  1075. bool IsRemoteAdminMode ()
  1076. {
  1077. // HKLM ,"SYSTEM\CurrentControlSet\Control\Terminal Server","TSAppCompat",0x00010001,0x0
  1078. CRegistry reg;
  1079. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ, CTSTestData::GetMachineName()))
  1080. {
  1081. DWORD dwAppCompat = 1;
  1082. if ( ERROR_SUCCESS == reg.ReadRegDWord( _T("TSAppCompat"), &dwAppCompat))
  1083. {
  1084. return dwAppCompat == 0;
  1085. }
  1086. else
  1087. {
  1088. // if the registry TSAppCompat does not exist it means we are in app server mode.
  1089. return false;
  1090. }
  1091. }
  1092. // this return is bogus.
  1093. return true;
  1094. }
  1095. EResult VerifyModeRegistry (ostrstream &ResultStream)
  1096. {
  1097. if (CheckModeRegistry(!IsRemoteAdminMode(), ResultStream))
  1098. {
  1099. ResultStream << "Passed";
  1100. return ePassed;
  1101. }
  1102. else
  1103. {
  1104. ResultStream << "Failed";
  1105. return eFailed;
  1106. }
  1107. }
  1108. bool CheckModeRegistry (bool bAppCompat, ostrstream &ResultStream)
  1109. {
  1110. USES_CONVERSION;
  1111. bool bOk = true;
  1112. CRegistry reg;
  1113. if (IsItServer())
  1114. {
  1115. CRegistry reg1;
  1116. if ( ERROR_SUCCESS == reg1.OpenKey( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), KEY_READ, CTSTestData::GetMachineName()))
  1117. {
  1118. LPTSTR str;
  1119. DWORD dwSize;
  1120. if (ERROR_SUCCESS == reg1.ReadRegString(_T("AppSetup"), &str, &dwSize))
  1121. {
  1122. if (bAppCompat)
  1123. {
  1124. if (_tcsicmp(str, _T("UsrLogon.Cmd")) != 0)
  1125. {
  1126. bOk = false;
  1127. ResultStream << "ERROR: Wrong value (" << T2A(str) << ") for AppSetup, contact makarp/breenh" << endl;
  1128. }
  1129. }
  1130. else
  1131. {
  1132. if (_tcslen(str) != 0)
  1133. {
  1134. bOk = false;
  1135. ResultStream << "ERROR: Wrong value (" << T2A(str) << ") for AppSetup, contact makarp/breenh" << endl;
  1136. }
  1137. }
  1138. }
  1139. else
  1140. {
  1141. ResultStream << "ERROR reading appsetup registry" << endl;
  1142. bOk = false;
  1143. }
  1144. }
  1145. else
  1146. {
  1147. ResultStream << "ERROR:reading SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" << endl;
  1148. bOk = false;
  1149. }
  1150. }
  1151. // check registry value
  1152. // for appcompat mode
  1153. //HKLM ,"SYSTEM\CurrentControlSet\Control\PriorityControl","Win32PrioritySeparation", 0x00010001,0x26
  1154. // and for remote admin mode
  1155. //HKLM ,"SYSTEM\CurrentControlSet\Control\PriorityControl","Win32PrioritySeparation", 0x00010001,0x18
  1156. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\PriorityControl"), KEY_READ, CTSTestData::GetMachineName()))
  1157. {
  1158. DWORD dwPriority;
  1159. if (ERROR_SUCCESS == reg.ReadRegDWord(_T("Win32PrioritySeparation"), &dwPriority))
  1160. {
  1161. if (bAppCompat)
  1162. {
  1163. if (0x26 != dwPriority)
  1164. {
  1165. bOk = false;
  1166. ResultStream << "ERROR: Wrong Win32PrioritySeparation (" << dwPriority << ")" << endl;
  1167. }
  1168. }
  1169. else if (IsItServer())
  1170. {
  1171. if (0x18 != dwPriority)
  1172. {
  1173. bOk = false;
  1174. ResultStream << "ERROR: Wrong Win32PrioritySeparation (" << dwPriority << ")" << endl;
  1175. }
  1176. }
  1177. }
  1178. else
  1179. {
  1180. bOk = false;
  1181. ResultStream << "ERROR:Reading Win32PrioritySeparation registry" << endl;
  1182. }
  1183. }
  1184. else
  1185. {
  1186. bOk = false;
  1187. ResultStream << "ERROR:Reading PriorityControl registry" << endl;
  1188. }
  1189. // check registry value
  1190. // for appcompat mode
  1191. //HKLM ,"SYSTEM\CurrentControlSet\Control\Terminal Server","IdleWinStationPoolCount",0x00010001,0x2
  1192. // and for remote admin mode
  1193. //HKLM ,"SYSTEM\CurrentControlSet\Control\Terminal Server","IdleWinStationPoolCount",0x00010001,0x0
  1194. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server"), KEY_READ, CTSTestData::GetMachineName()))
  1195. {
  1196. DWORD dwIdleWinstations;
  1197. if (ERROR_SUCCESS == reg.ReadRegDWord(_T("IdleWinStationPoolCount"), &dwIdleWinstations))
  1198. {
  1199. if (bAppCompat)
  1200. {
  1201. if (0x2 != dwIdleWinstations)
  1202. {
  1203. bOk = false;
  1204. ResultStream << "ERROR: Wrong IdleWinStationPoolCount (" << dwIdleWinstations << ")" << endl;
  1205. }
  1206. }
  1207. else
  1208. {
  1209. if (0 != dwIdleWinstations)
  1210. {
  1211. bOk = false;
  1212. ResultStream << "ERROR: Wrong IdleWinStationPoolCount (" << dwIdleWinstations << ")" << endl;
  1213. }
  1214. }
  1215. }
  1216. else
  1217. {
  1218. bOk = false;
  1219. ResultStream << "ERROR:Reading IdleWinStationPoolCount registry" << endl;
  1220. }
  1221. }
  1222. else
  1223. {
  1224. bOk = false;
  1225. ResultStream << "SYSTEM\\CurrentControlSet\\Control\\Terminal Server" << endl;
  1226. }
  1227. return bOk;
  1228. }
  1229. bool g_IsTermsrvRunning = false;
  1230. bool IsTerminalServiceRunning ()
  1231. {
  1232. return g_IsTermsrvRunning;
  1233. }
  1234. EResult IsTerminalServiceRunning (ostrstream &ResultStream)
  1235. {
  1236. EResult eRes = eUnknown;
  1237. bool bReturn = false;
  1238. SC_HANDLE hServiceController = OpenSCManager(CTSTestData::GetMachineNamePath(), NULL, GENERIC_READ);
  1239. if (hServiceController)
  1240. {
  1241. SC_HANDLE hTermServ = OpenService(hServiceController, _T("TermService"), SERVICE_QUERY_STATUS);
  1242. if (hTermServ)
  1243. {
  1244. SERVICE_STATUS tTermServStatus;
  1245. if (QueryServiceStatus(hTermServ, &tTermServStatus))
  1246. {
  1247. bReturn = (tTermServStatus.dwCurrentState == SERVICE_RUNNING);
  1248. if (bReturn)
  1249. {
  1250. ResultStream << "Passed";
  1251. eRes = ePassed;
  1252. g_IsTermsrvRunning = true;
  1253. }
  1254. else
  1255. {
  1256. ResultStream << "Failed, Termsrv is not running";
  1257. eRes = eFailed;
  1258. }
  1259. }
  1260. else
  1261. {
  1262. ResultStream << "Failed to get service status, Error = " << GetLastError();
  1263. eRes = eFailedToExecute;
  1264. }
  1265. VERIFY(CloseServiceHandle(hTermServ));
  1266. }
  1267. else
  1268. {
  1269. ResultStream << "Failed to open TermServ service, Error = " << GetLastError() << endl;
  1270. eRes = eFailedToExecute;
  1271. }
  1272. VERIFY(CloseServiceHandle(hServiceController));
  1273. }
  1274. else
  1275. {
  1276. ResultStream << "Failed to Open Service Controller, Error = " << GetLastError() << endl;
  1277. eRes = eFailedToExecute;
  1278. }
  1279. return eRes;
  1280. }
  1281. EResult CheckVideoKeys (ostrstream &ResultStream)
  1282. {
  1283. // HKLM ,"SYSTEM\CurrentControlSet\Control\Terminal Server\VIDEO\rdpdd","VgaCompatible",0x00000000,"\Device\Video0"
  1284. // HKLM ,"SYSTEM\CurrentControlSet\Control\Terminal Server\VIDEO\rdpdd","\Device\Video0",0x00000000,"\REGISTRY\Machine\System\ControlSet001\Services\RDPDD\Device0"
  1285. CRegistry reg;
  1286. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\VIDEO\\rdpdd"), KEY_READ, CTSTestData::GetMachineName()))
  1287. {
  1288. LPTSTR str = 0;
  1289. DWORD dwSize = 0;
  1290. if (ERROR_SUCCESS == reg.ReadRegString(_T("VgaCompatible"), &str, &dwSize))
  1291. {
  1292. if (0 == _tcsicmp(str, _T("\\Device\\Video0")))
  1293. {
  1294. if (ERROR_SUCCESS == reg.ReadRegString(_T("\\Device\\Video0"), &str, &dwSize))
  1295. {
  1296. if ((0 == _tcsicmp(str, _T("\\REGISTRY\\Machine\\System\\ControlSet001\\Services\\RDPDD\\Device0"))) ||
  1297. (0 == _tcsicmp(str, _T("\\REGISTRY\\Machine\\System\\CurrentControlSet\\Services\\RDPDD\\Device0"))))
  1298. {
  1299. ResultStream << "Passed";
  1300. return ePassed;
  1301. }
  1302. else
  1303. {
  1304. }
  1305. }
  1306. else
  1307. {
  1308. }
  1309. }
  1310. else
  1311. {
  1312. }
  1313. }
  1314. else
  1315. {
  1316. }
  1317. }
  1318. else
  1319. {
  1320. }
  1321. ResultStream << "Failed";
  1322. return eFailed;
  1323. }
  1324. TCHAR szCompName[256];
  1325. EResult GetCompName (ostrstream &ResultStream)
  1326. {
  1327. USES_CONVERSION;
  1328. if (!CTSTestData::GetMachineName())
  1329. {
  1330. DWORD dwCompName = 256;
  1331. if (GetComputerName(szCompName, &dwCompName))
  1332. {
  1333. ResultStream << T2A(szCompName);
  1334. return ePassed;
  1335. }
  1336. return eFailedToExecute;
  1337. }
  1338. else
  1339. {
  1340. _tcscpy(szCompName, CTSTestData::GetMachineName());
  1341. ResultStream << T2A(CTSTestData::GetMachineName());
  1342. return ePassed;
  1343. }
  1344. }
  1345. bool g_bIsInDomain = false;
  1346. EResult GetDomName (ostrstream &ResultStream)
  1347. {
  1348. USES_CONVERSION;
  1349. DSROLE_PRIMARY_DOMAIN_INFO_BASIC *pDomainInfo = NULL;
  1350. DWORD dwErr;
  1351. //
  1352. // Check if we're in a workgroup
  1353. //
  1354. dwErr = DsRoleGetPrimaryDomainInformation(CTSTestData::GetMachineName(),
  1355. DsRolePrimaryDomainInfoBasic,
  1356. (PBYTE *) &pDomainInfo);
  1357. if (ERROR_SUCCESS != dwErr)
  1358. {
  1359. ResultStream << "<Unknown Domain>";
  1360. return eFailedToExecute;
  1361. }
  1362. switch (pDomainInfo->MachineRole)
  1363. {
  1364. case DsRole_RoleStandaloneWorkstation:
  1365. case DsRole_RoleStandaloneServer:
  1366. ResultStream << "<Workgroup>";
  1367. return ePassed;
  1368. default:
  1369. break;
  1370. }
  1371. if (pDomainInfo->DomainNameFlat)
  1372. {
  1373. ResultStream << T2A(pDomainInfo->DomainNameFlat);
  1374. g_bIsInDomain = true;
  1375. return ePassed;
  1376. }
  1377. else if (pDomainInfo->DomainNameDns)
  1378. {
  1379. ResultStream << T2A(pDomainInfo->DomainNameDns);
  1380. g_bIsInDomain = true;
  1381. return ePassed;
  1382. }
  1383. else
  1384. {
  1385. ResultStream << "<Unknown Domain>";
  1386. return eFailedToExecute;
  1387. }
  1388. }
  1389. EResult GetIPAddress (ostrstream &ResultStream)
  1390. {
  1391. USES_CONVERSION;
  1392. WCHAR wszIPAddress[128];
  1393. //
  1394. //get host address
  1395. //
  1396. WORD wVersionRequested = MAKEWORD( 1, 1 );
  1397. WSADATA wsaData;
  1398. if (0 == WSAStartup(wVersionRequested,&wsaData))
  1399. {
  1400. hostent *h;
  1401. if (NULL != (h=gethostbyname ( T2A(CTSTestData::GetMachineName()) )))
  1402. {
  1403. in_addr *inaddr=(struct in_addr *)*h->h_addr_list;
  1404. MultiByteToWideChar(CP_ACP,0,inet_ntoa(*inaddr),-1,wszIPAddress,128);
  1405. ResultStream << W2A(wszIPAddress);
  1406. return ePassed;
  1407. }
  1408. }
  1409. ResultStream << "Error Getting IP";
  1410. return eFailedToExecute;
  1411. }
  1412. EResult IsRDPNPinNetProviders (ostrstream &ResultStream)
  1413. // TCHAR *IsRDPNPinNetProviders ()
  1414. {
  1415. TCHAR NEWORK_PROVIDER_ORDER_KEY[] = _T("SYSTEM\\CurrentControlSet\\Control\\NetworkProvider\\Order");
  1416. TCHAR PROVIDER_ORDER_VALUE[] = _T("ProviderOrder");
  1417. TCHAR RDPNP_ENTRY[] = _T("RDPNP");
  1418. bool bRdpNpExists = false;
  1419. // read network privider key.
  1420. CRegistry regNetOrder;
  1421. LPTSTR szOldValue;
  1422. DWORD dwSize;
  1423. if ((ERROR_SUCCESS == regNetOrder.OpenKey(HKEY_LOCAL_MACHINE, NEWORK_PROVIDER_ORDER_KEY, KEY_READ, CTSTestData::GetMachineName())) &&
  1424. (ERROR_SUCCESS == regNetOrder.ReadRegString(PROVIDER_ORDER_VALUE, &szOldValue, &dwSize)))
  1425. {
  1426. bRdpNpExists = (_tcsstr(szOldValue, RDPNP_ENTRY) != NULL);
  1427. }
  1428. else
  1429. {
  1430. ResultStream << "Error: Failed to Read Registry!";
  1431. return eFailedToExecute;
  1432. }
  1433. if (TSEnabled () == bRdpNpExists)
  1434. {
  1435. ResultStream << "Passed";
  1436. return ePassed;
  1437. }
  1438. else
  1439. {
  1440. if (bRdpNpExists)
  1441. {
  1442. ResultStream << "Error: RDPNP, exists in ProviderOrder, but TS is disabled!";
  1443. return eFailed;
  1444. }
  1445. else
  1446. {
  1447. if (IsIt50TS())
  1448. {
  1449. // rdp np is only for 51+ so its ok if its missing for 50.
  1450. ResultStream << "Passed";
  1451. return ePassed;
  1452. }
  1453. else
  1454. {
  1455. ResultStream << "ERROR, RDPNP is missing from ProviderOrder";
  1456. return eFailed;
  1457. }
  1458. }
  1459. }
  1460. }
  1461. EResult IsMultiConnectionAllowed (ostrstream &ResultStream)
  1462. // TCHAR *IsMultiConnectionAllowed ()
  1463. {
  1464. // SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","AllowMultipleTSSessions
  1465. CRegistry regWL;
  1466. DWORD dwAllowMultipal;
  1467. if ((ERROR_SUCCESS == regWL.OpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), KEY_READ, CTSTestData::GetMachineName())) &&
  1468. (ERROR_SUCCESS == regWL.ReadRegDWord(_T("AllowMultipleTSSessions"), &dwAllowMultipal)))
  1469. {
  1470. if (dwAllowMultipal)
  1471. {
  1472. ResultStream << "Yes";
  1473. }
  1474. else
  1475. {
  1476. ResultStream << "No";
  1477. }
  1478. return ePassed;
  1479. }
  1480. if (IsIt50TS())
  1481. {
  1482. ResultStream << "Yes";
  1483. return ePassed;
  1484. }
  1485. else
  1486. {
  1487. ResultStream << "ERROR, registry missing";
  1488. return eFailedToExecute;
  1489. }
  1490. }
  1491. EResult LogonType (ostrstream &ResultStream)
  1492. // TCHAR *LogonType ()
  1493. {
  1494. if (!g_bIsInDomain)
  1495. {
  1496. CRegistry regWL;
  1497. DWORD dwLogonType;
  1498. if ((ERROR_SUCCESS == regWL.OpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), KEY_READ, CTSTestData::GetMachineName())) &&
  1499. (ERROR_SUCCESS == regWL.ReadRegDWord(_T("LogonType"), &dwLogonType)))
  1500. {
  1501. if (dwLogonType == 0)
  1502. {
  1503. ResultStream << "Classic Gina";
  1504. }
  1505. else
  1506. {
  1507. ResultStream << "New Fancy";
  1508. }
  1509. return ePassed;
  1510. }
  1511. if (IsIt50TS())
  1512. {
  1513. ResultStream << "Classic Gina";
  1514. return ePassed;
  1515. }
  1516. else
  1517. {
  1518. ResultStream << "ERROR, registry missing";
  1519. return eFailedToExecute;
  1520. }
  1521. }
  1522. else
  1523. {
  1524. ResultStream << "Classic Gina";
  1525. return ePassed;
  1526. }
  1527. }
  1528. EResult IsTermSrvInSystemContext (ostrstream &ResultStream)
  1529. // bool IsTermSrvInSystemContext ()
  1530. {
  1531. USES_CONVERSION;
  1532. CRegistry reg;
  1533. if ( ERROR_SUCCESS == reg.OpenKey( HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\TermService"), KEY_READ, CTSTestData::GetMachineName()))
  1534. {
  1535. TCHAR *szObjectName;
  1536. DWORD dwSize;
  1537. if ( ERROR_SUCCESS == reg.ReadRegString( _T("ObjectName"), &szObjectName, &dwSize))
  1538. {
  1539. if (0 == _tcsicmp(szObjectName, _T("LocalSystem")))
  1540. {
  1541. ResultStream << "Passed";
  1542. return ePassed;
  1543. }
  1544. else
  1545. {
  1546. ResultStream << "ERROR:Termsrv is set to run using (" << T2A(szObjectName) << ") context." << endl;
  1547. return eFailed;
  1548. }
  1549. }
  1550. else
  1551. {
  1552. ResultStream << "failed to read Objectname";
  1553. return eFailedToExecute;
  1554. }
  1555. }
  1556. else
  1557. {
  1558. ResultStream << "failed to open termsrv registry";
  1559. return eFailedToExecute;
  1560. }
  1561. }
  1562. EResult IsBetaSystem (ostrstream &ResultStream)
  1563. {
  1564. ASSERT (IsItLocalMachine());
  1565. if (IsBetaSystem())
  1566. {
  1567. ResultStream << "Its a beta system";
  1568. }
  1569. else
  1570. {
  1571. ResultStream << "Its a retail build";
  1572. }
  1573. return ePassed;
  1574. }
  1575. EResult AreRemoteLogonEnabled (ostrstream &ResultStream)
  1576. {
  1577. CRegistry oRegTermsrv;
  1578. if (ERROR_SUCCESS == oRegTermsrv.OpenKey(
  1579. HKEY_LOCAL_MACHINE,
  1580. _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"),
  1581. KEY_READ,
  1582. CTSTestData::GetMachineName()
  1583. ))
  1584. {
  1585. DWORD dwSize = 0;
  1586. LPTSTR szWinstationDisabled = NULL;
  1587. if (ERROR_SUCCESS == oRegTermsrv.ReadRegString(_T("WinStationsDisabled"), &szWinstationDisabled, &dwSize))
  1588. {
  1589. if (_tcscmp(_T("0"), szWinstationDisabled) == 0)
  1590. {
  1591. ResultStream << "Passed";
  1592. return ePassed;
  1593. }
  1594. else
  1595. {
  1596. USES_CONVERSION;
  1597. ResultStream << "Failed, WinStationsDisabled is (" << T2A(szWinstationDisabled) << ")";
  1598. return eFailed;
  1599. }
  1600. }
  1601. else
  1602. {
  1603. ResultStream << "Failed to red registry";
  1604. return eFailedToExecute;
  1605. }
  1606. }
  1607. else
  1608. {
  1609. ResultStream << "Failed to read registry";
  1610. return eFailedToExecute;
  1611. }
  1612. }
  1613. EResult IsListenerSessionPresent(ostrstream &ResultStream)
  1614. {
  1615. PWTS_SESSION_INFO pWtsSessionInfo;
  1616. DWORD dwCount;
  1617. bool bReturn = false;
  1618. HANDLE hServer = WTS_CURRENT_SERVER_HANDLE;
  1619. if (CTSTestData::GetMachineName())
  1620. {
  1621. TCHAR szMachineName[256];
  1622. _tcscpy(szMachineName, CTSTestData::GetMachineName());
  1623. hServer = WTSOpenServer (szMachineName);
  1624. }
  1625. if (WTSEnumerateSessions(
  1626. hServer,
  1627. 0,
  1628. 1,
  1629. &pWtsSessionInfo,
  1630. &dwCount
  1631. ))
  1632. {
  1633. for (DWORD i = 0; i < dwCount; i++)
  1634. {
  1635. if (pWtsSessionInfo[i].State == WTSListen)
  1636. {
  1637. bReturn = true;
  1638. break;
  1639. }
  1640. }
  1641. WTSFreeMemory(pWtsSessionInfo);
  1642. }
  1643. else
  1644. {
  1645. ResultStream << "WTSEnumerateSessions failed!";
  1646. return eFailedToExecute;
  1647. }
  1648. if (CTSTestData::GetMachineName())
  1649. WTSCloseServer(hServer);
  1650. if (bReturn)
  1651. {
  1652. ResultStream << "Passed!";
  1653. return ePassed;
  1654. }
  1655. else
  1656. {
  1657. ResultStream << "Failed!";
  1658. return eFailed;
  1659. }
  1660. }
  1661. ULONG ulClientBuildNumber = 0xffffffff;
  1662. bool GetClientVersion(ULONG *pulClientBuildNumber)
  1663. {
  1664. ASSERT(AreWeInsideSession());
  1665. ASSERT(pulClientBuildNumber);
  1666. if (ulClientBuildNumber == 0xffffffff)
  1667. {
  1668. LPTSTR pBuffer = NULL;
  1669. DWORD dwBytesReturned = 0;
  1670. if (WTSQuerySessionInformation(
  1671. WTS_CURRENT_SERVER_HANDLE,
  1672. WTS_CURRENT_SESSION,
  1673. WTSClientBuildNumber,
  1674. &pBuffer,
  1675. &dwBytesReturned))
  1676. {
  1677. if (pBuffer && dwBytesReturned)
  1678. {
  1679. ulClientBuildNumber = ULONG(*pBuffer);
  1680. *pulClientBuildNumber = ulClientBuildNumber;
  1681. WTSFreeMemory(pBuffer);
  1682. return true;
  1683. }
  1684. else
  1685. {
  1686. return false;
  1687. }
  1688. }
  1689. else
  1690. {
  1691. return false;
  1692. }
  1693. }
  1694. else
  1695. {
  1696. *pulClientBuildNumber = ulClientBuildNumber;
  1697. return true;
  1698. }
  1699. }
  1700. USHORT gusClientProtocol = 0xffff;
  1701. bool GetClientProtocol (USHORT *pusClientProtocol)
  1702. {
  1703. ASSERT(AreWeInsideSession());
  1704. ASSERT(pusClientProtocol);
  1705. if (gusClientProtocol == 0xffff)
  1706. {
  1707. LPTSTR pBuffer = NULL;
  1708. DWORD dwBytesReturned = 0;
  1709. if (WTSQuerySessionInformation(
  1710. WTS_CURRENT_SERVER_HANDLE,
  1711. WTS_CURRENT_SESSION,
  1712. WTSClientProtocolType,
  1713. &pBuffer,
  1714. &dwBytesReturned))
  1715. {
  1716. if (pBuffer && dwBytesReturned)
  1717. {
  1718. gusClientProtocol = USHORT(*pBuffer);
  1719. *pusClientProtocol = gusClientProtocol;
  1720. WTSFreeMemory(pBuffer);
  1721. return true;
  1722. }
  1723. else
  1724. {
  1725. return false;
  1726. }
  1727. }
  1728. else
  1729. {
  1730. return false;
  1731. }
  1732. }
  1733. else
  1734. {
  1735. *pusClientProtocol = gusClientProtocol;
  1736. return true;
  1737. }
  1738. }
  1739. EResult GetClientVersion(ostrstream &ResultStream)
  1740. {
  1741. ULONG ulClientVersion;
  1742. ASSERT(AreWeInsideSession());
  1743. if (GetClientVersion(&ulClientVersion))
  1744. {
  1745. ResultStream << ulClientVersion;
  1746. return ePassed;
  1747. }
  1748. else
  1749. {
  1750. ResultStream << "Failed to retrive client version";
  1751. return eFailedToExecute;
  1752. }
  1753. }
  1754. EResult GetClientProtocol(ostrstream &ResultStream)
  1755. {
  1756. USHORT usClientProtocol;
  1757. ASSERT(AreWeInsideSession());
  1758. if (GetClientProtocol(&usClientProtocol))
  1759. {
  1760. switch (usClientProtocol)
  1761. {
  1762. case WTS_PROTOCOL_TYPE_CONSOLE:
  1763. ResultStream << "WTS_PROTOCOL_TYPE_CONSOLE(" << usClientProtocol << ")";
  1764. break;
  1765. case WTS_PROTOCOL_TYPE_ICA:
  1766. ResultStream << "WTS_PROTOCOL_TYPE_ICA(" << usClientProtocol << ")";
  1767. break;
  1768. case WTS_PROTOCOL_TYPE_RDP:
  1769. ResultStream << "WTS_PROTOCOL_TYPE_RDP(" << usClientProtocol << ")";
  1770. break;
  1771. default:
  1772. ResultStream << "Unknown Protocol Value(" << usClientProtocol << ")";
  1773. break;
  1774. }
  1775. return ePassed;
  1776. }
  1777. else
  1778. {
  1779. ResultStream << "Failed to retrive client protocol";
  1780. return eFailedToExecute;
  1781. }
  1782. }
  1783. EResult DoesClientSupportAudioRedirection (ostrstream &ResultStream)
  1784. {
  1785. ASSERT(AreWeInsideSession());
  1786. const USHORT GOOD_CLIENT_VERSION_FOR_AUDIO_REDIRECTION = 2252;
  1787. ULONG ulClientVersion;
  1788. USHORT usClientProtocol;
  1789. if (GetClientVersion(&ulClientVersion) && GetClientProtocol(&usClientProtocol))
  1790. {
  1791. if (ulClientVersion >= GOOD_CLIENT_VERSION_FOR_AUDIO_REDIRECTION && usClientProtocol == WTS_PROTOCOL_TYPE_RDP)
  1792. {
  1793. ResultStream << "Passed";
  1794. return ePassed;
  1795. }
  1796. else
  1797. {
  1798. if (ulClientVersion < GOOD_CLIENT_VERSION_FOR_AUDIO_REDIRECTION )
  1799. {
  1800. ResultStream << "Failed. You client is old, it does not support audio redirection.";
  1801. }
  1802. else if(usClientProtocol != WTS_PROTOCOL_TYPE_RDP)
  1803. {
  1804. ResultStream << "Failed. You client is not Microsoft RDP, it may not support audio redirection.";
  1805. }
  1806. else
  1807. {
  1808. ASSERT(false);
  1809. }
  1810. return eFailed;
  1811. }
  1812. }
  1813. else
  1814. {
  1815. ResultStream << "Failed to get client version";
  1816. return eFailedToExecute;
  1817. }
  1818. }
  1819. EResult DoesClientSupportPrinterRedirection (ostrstream &ResultStream)
  1820. {
  1821. ASSERT(AreWeInsideSession());
  1822. const USHORT GOOD_CLIENT_VERSION_FOR_PRINTER_REDIRECTION = 2100; // BUGBUG :get good value for this from tADB
  1823. ULONG ulClientVersion;
  1824. USHORT usClientProtocol;
  1825. if (GetClientVersion(&ulClientVersion) && GetClientProtocol(&usClientProtocol))
  1826. {
  1827. if (ulClientVersion >= GOOD_CLIENT_VERSION_FOR_PRINTER_REDIRECTION && usClientProtocol == WTS_PROTOCOL_TYPE_RDP)
  1828. {
  1829. ResultStream << "Passed";
  1830. return ePassed;
  1831. }
  1832. else
  1833. {
  1834. if (ulClientVersion < GOOD_CLIENT_VERSION_FOR_PRINTER_REDIRECTION )
  1835. {
  1836. ResultStream << "Failed. You client is old, it does not support printer redirection.";
  1837. }
  1838. else if(usClientProtocol != WTS_PROTOCOL_TYPE_RDP)
  1839. {
  1840. ResultStream << "Failed. You client is not Microsoft RDP, it may not support printer redirection.";
  1841. }
  1842. else
  1843. {
  1844. ASSERT(false);
  1845. }
  1846. return eFailed;
  1847. }
  1848. }
  1849. else
  1850. {
  1851. ResultStream << "Failed to get client version";
  1852. return eFailedToExecute;
  1853. }
  1854. }
  1855. EResult DoesClientSupportFileRedirection (ostrstream &ResultStream)
  1856. {
  1857. ASSERT(AreWeInsideSession());
  1858. const USHORT GOOD_CLIENT_VERSION_FOR_FILE_REDIRECTION = 2200; // BUGBUG :get good value for this from tADB
  1859. ULONG ulClientVersion;
  1860. USHORT usClientProtocol;
  1861. if (GetClientVersion(&ulClientVersion) && GetClientProtocol(&usClientProtocol))
  1862. {
  1863. if (ulClientVersion >= GOOD_CLIENT_VERSION_FOR_FILE_REDIRECTION && usClientProtocol == WTS_PROTOCOL_TYPE_RDP)
  1864. {
  1865. ResultStream << "Passed";
  1866. return ePassed;
  1867. }
  1868. else
  1869. {
  1870. if (ulClientVersion < GOOD_CLIENT_VERSION_FOR_FILE_REDIRECTION )
  1871. {
  1872. ResultStream << "Failed. You client is old, it does not support file redirection.";
  1873. }
  1874. else if(usClientProtocol != WTS_PROTOCOL_TYPE_RDP)
  1875. {
  1876. ResultStream << "Failed. You client is not Microsoft RDP, it may not support file redirection.";
  1877. }
  1878. else
  1879. {
  1880. ASSERT(false);
  1881. }
  1882. return eFailed;
  1883. }
  1884. }
  1885. else
  1886. {
  1887. ResultStream << "Failed to get client version";
  1888. return eFailedToExecute;
  1889. }
  1890. }
  1891. EResult DoesClientSupportClipboardRedirection (ostrstream &ResultStream)
  1892. {
  1893. ASSERT(AreWeInsideSession());
  1894. const USHORT GOOD_CLIENT_VERSION_FOR_FILE_REDIRECTION = 2100; // BUGBUG :get good value for this from Nadim
  1895. ULONG ulClientVersion;
  1896. USHORT usClientProtocol;
  1897. if (GetClientVersion(&ulClientVersion) && GetClientProtocol(&usClientProtocol))
  1898. {
  1899. if (ulClientVersion >= GOOD_CLIENT_VERSION_FOR_FILE_REDIRECTION && usClientProtocol == WTS_PROTOCOL_TYPE_RDP)
  1900. {
  1901. ResultStream << "Passed";
  1902. return ePassed;
  1903. }
  1904. else
  1905. {
  1906. if (ulClientVersion < GOOD_CLIENT_VERSION_FOR_FILE_REDIRECTION )
  1907. {
  1908. ResultStream << "Failed. You client is old, it does not support Clipboard redirection.";
  1909. }
  1910. else if(usClientProtocol != WTS_PROTOCOL_TYPE_RDP)
  1911. {
  1912. ResultStream << "Failed. You client is not Microsoft RDP, it may not support Clipboard redirection.";
  1913. }
  1914. else
  1915. {
  1916. ASSERT(false);
  1917. }
  1918. return eFailed;
  1919. }
  1920. }
  1921. else
  1922. {
  1923. ResultStream << "Failed to get client version";
  1924. return eFailedToExecute;
  1925. }
  1926. }
  1927. // #define TS_POLICY_SUB_TREE L"Software\\Policies\\Microsoft\\Windows NT\\Terminal Services"
  1928. bool GetWinstationInformation(WINSTATIONINFORMATION **ppInfo)
  1929. {
  1930. ASSERT(ppInfo);
  1931. ASSERT(AreWeInsideSession());
  1932. static bool sbGotWinstaInfo = false;
  1933. static WINSTATIONINFORMATION WSInfo;
  1934. ULONG ReturnLength;
  1935. if (sbGotWinstaInfo)
  1936. {
  1937. *ppInfo = &WSInfo;
  1938. return true;
  1939. }
  1940. if (WinStationQueryInformation(
  1941. WTS_CURRENT_SERVER_HANDLE,
  1942. WTS_CURRENT_SESSION,
  1943. WinStationInformation,
  1944. &WSInfo,
  1945. sizeof(WSInfo),
  1946. &ReturnLength
  1947. ))
  1948. {
  1949. sbGotWinstaInfo = true;
  1950. *ppInfo = &WSInfo;
  1951. return true;
  1952. }
  1953. return false;
  1954. }
  1955. bool GetWinstationConfiguration (WINSTATIONCONFIG **ppInfo)
  1956. {
  1957. ASSERT(ppInfo);
  1958. ASSERT(AreWeInsideSession());
  1959. static bool sbGotWinstaConfig = false;
  1960. static WINSTATIONCONFIG WSConfig;
  1961. ULONG ReturnLength;
  1962. if (sbGotWinstaConfig)
  1963. {
  1964. *ppInfo = &WSConfig;
  1965. return true;
  1966. }
  1967. if (WinStationQueryInformation(
  1968. WTS_CURRENT_SERVER_HANDLE,
  1969. WTS_CURRENT_SESSION,
  1970. WinStationConfiguration,
  1971. &WSConfig,
  1972. sizeof(WSConfig),
  1973. &ReturnLength
  1974. ))
  1975. {
  1976. sbGotWinstaConfig = true;
  1977. *ppInfo = &WSConfig;
  1978. return true;
  1979. }
  1980. return false;
  1981. }
  1982. EResult GetUserName(ostrstream &ResultStream)
  1983. {
  1984. USES_CONVERSION;
  1985. ASSERT(AreWeInsideSession());
  1986. WINSTATIONINFORMATION *pWSInfo = NULL;
  1987. if (GetWinstationInformation(&pWSInfo))
  1988. {
  1989. TCHAR szUser[256];
  1990. _tcscpy(szUser, pWSInfo->Domain);
  1991. _tcscat(szUser, _T("\\"));
  1992. _tcscat(szUser, pWSInfo->UserName);
  1993. ResultStream << T2A(szUser);
  1994. return ePassed;
  1995. }
  1996. ResultStream << "Failed to get UserName";
  1997. return eFailedToExecute;
  1998. }
  1999. EResult GetPolicy (ostrstream &ResultStream)
  2000. {
  2001. USES_CONVERSION;
  2002. ASSERT(AreWeInsideSession());
  2003. WINSTATIONCONFIG *pWSInfo = NULL;
  2004. if (GetWinstationConfiguration(&pWSInfo))
  2005. {
  2006. /*
  2007. ResultStream << "fPromptForPassword" << pWSInfo->User.fPromptForPassword << "," << endl;
  2008. ResultStream << "fResetBroken" << pWSInfo->User.fResetBroken << "," << endl;
  2009. ResultStream << "fReconnectSame " << pWSInfo->User.fReconnectSame << "," << endl;
  2010. ResultStream << "fLogonDisabled " << pWSInfo->User.fLogonDisabled << "," << endl;;
  2011. ResultStream << "fWallPaperDisabled" << pWSInfo->User.fWallPaperDisabled << "," << endl;
  2012. ResultStream << "fAutoClientDrives" << pWSInfo->User.fAutoClientDrives << "," << endl;
  2013. ResultStream << "fAutoClientLpts" << pWSInfo->User.fAutoClientLpts << "," << endl;
  2014. ResultStream << "fForceClientLptDef" << pWSInfo->User.fForceClientLptDef << "," << endl;
  2015. ResultStream << "fRequireEncryption" << pWSInfo->User.fRequireEncryption << "," << endl;
  2016. ResultStream << "fDisableEncryption" << pWSInfo->User.fDisableEncryption << "," << endl;
  2017. ResultStream << "fUnused1" << pWSInfo->User.fUnused1 << "," << endl;
  2018. ResultStream << "fHomeDirectoryMapRoot" << pWSInfo->User.fHomeDirectoryMapRoot << "," << endl;
  2019. ResultStream << "fUseDefaultGina" << pWSInfo->User.fUseDefaultGina << "," << endl;
  2020. */
  2021. /*
  2022. ULONG fDisableCpm : 1;
  2023. for printing
  2024. ULONG fDisableCdm : 1;
  2025. for drive
  2026. ULONG fDisableCcm : 1;
  2027. for com port
  2028. ULONG fDisableLPT : 1;
  2029. for lpt port
  2030. ULONG fDisableClip : 1;
  2031. for clipboard redirection
  2032. ULONG fDisableExe : 1;
  2033. ULONG fDisableCam : 1;
  2034. for audio redirection
  2035. ULONG ColorDepth : 3;
  2036. Color depth.
  2037. */
  2038. ResultStream << "printer redirection = " << pWSInfo->User.fDisableCpm << endl;
  2039. ResultStream << "drive redirection = " << pWSInfo->User.fDisableCdm << endl;
  2040. ResultStream << "com port redirection = " << pWSInfo->User.fDisableCcm << endl;
  2041. ResultStream << "LPT port redirection = " << pWSInfo->User.fDisableLPT << endl;
  2042. ResultStream << "Clipboard redirection =" << pWSInfo->User.fDisableClip << endl;
  2043. ResultStream << "fDisableExe = " << pWSInfo->User.fDisableExe << endl;
  2044. ResultStream << "Audio Redireciton = " << pWSInfo->User.fDisableCam << endl;
  2045. return ePassed;
  2046. }
  2047. else
  2048. {
  2049. ResultStream << "Failed to get config data";
  2050. return eFailedToExecute;
  2051. }
  2052. }
  2053. EResult CanRedirectPrinter (ostrstream &ResultStream)
  2054. {
  2055. USES_CONVERSION;
  2056. ASSERT(AreWeInsideSession());
  2057. WINSTATIONCONFIG *pWSInfo = NULL;
  2058. if (GetWinstationConfiguration(&pWSInfo))
  2059. {
  2060. if (pWSInfo->User.fDisableCpm)
  2061. {
  2062. ResultStream << "Failed. Printer Redirection is disabled either by Group Policy or TSCC settings.";
  2063. return eFailed;
  2064. }
  2065. else
  2066. {
  2067. ResultStream << "Passed";
  2068. return ePassed;
  2069. }
  2070. }
  2071. else
  2072. {
  2073. ResultStream << "Failed to retrive config data";
  2074. return eFailedToExecute;
  2075. }
  2076. }
  2077. EResult CanRedirectDrives(ostrstream &ResultStream)
  2078. {
  2079. USES_CONVERSION;
  2080. ASSERT(AreWeInsideSession());
  2081. WINSTATIONCONFIG *pWSInfo = NULL;
  2082. if (GetWinstationConfiguration(&pWSInfo))
  2083. {
  2084. if (pWSInfo->User.fDisableCdm)
  2085. {
  2086. ResultStream << "Failed. Local Drive Redirection is disabled either by Group Policy or TSCC settings.";
  2087. return eFailed;
  2088. }
  2089. else
  2090. {
  2091. ResultStream << "Passed";
  2092. return ePassed;
  2093. }
  2094. }
  2095. else
  2096. {
  2097. ResultStream << "Failed to retrive config data";
  2098. return eFailedToExecute;
  2099. }
  2100. }
  2101. EResult CanRedirectClipboard(ostrstream &ResultStream)
  2102. {
  2103. USES_CONVERSION;
  2104. ASSERT(AreWeInsideSession());
  2105. WINSTATIONCONFIG *pWSInfo = NULL;
  2106. if (GetWinstationConfiguration(&pWSInfo))
  2107. {
  2108. if (pWSInfo->User.fDisableClip)
  2109. {
  2110. ResultStream << "Failed. Clipboard redirection is disabled either by Group Policy or TSCC settings.";
  2111. return eFailed;
  2112. }
  2113. else
  2114. {
  2115. ResultStream << "Passed";
  2116. return ePassed;
  2117. }
  2118. }
  2119. else
  2120. {
  2121. ResultStream << "Failed to retrive config data";
  2122. return eFailedToExecute;
  2123. }
  2124. }
  2125. EResult CanRedirectCom(ostrstream &ResultStream)
  2126. {
  2127. USES_CONVERSION;
  2128. ASSERT(AreWeInsideSession());
  2129. WINSTATIONCONFIG *pWSInfo = NULL;
  2130. if (GetWinstationConfiguration(&pWSInfo))
  2131. {
  2132. if (pWSInfo->User.fDisableCcm)
  2133. {
  2134. ResultStream << "Failed. Com port Redirection is disabled either by Group Policy or TSCC settings.";
  2135. return eFailed;
  2136. }
  2137. else
  2138. {
  2139. ResultStream << "Passed";
  2140. return ePassed;
  2141. }
  2142. }
  2143. else
  2144. {
  2145. ResultStream << "Failed to retrive config data";
  2146. return eFailedToExecute;
  2147. }
  2148. }
  2149. EResult CanRedirectAudio(ostrstream &ResultStream)
  2150. {
  2151. USES_CONVERSION;
  2152. ASSERT(AreWeInsideSession());
  2153. WINSTATIONCONFIG *pWSInfo = NULL;
  2154. if (GetWinstationConfiguration(&pWSInfo))
  2155. {
  2156. if (pWSInfo->User.fDisableCam)
  2157. {
  2158. ResultStream << "Failed. Audio Redirection is disabled either by Group Policy or TSCC settings.";
  2159. return eFailed;
  2160. }
  2161. else
  2162. {
  2163. ResultStream << "Passed";
  2164. return ePassed;
  2165. }
  2166. }
  2167. else
  2168. {
  2169. ResultStream << "Failed to retrive config data";
  2170. return eFailedToExecute;
  2171. }
  2172. }
  2173. EResult CanClientPlayAudio(ostrstream &ResultStream)
  2174. {
  2175. EResult rv = eFailedToExecute;
  2176. HANDLE hStream = NULL;
  2177. PSNDSTREAM Stream = NULL;
  2178. hStream = OpenFileMapping(
  2179. FILE_MAP_ALL_ACCESS,
  2180. FALSE,
  2181. TSSND_STREAMNAME
  2182. );
  2183. if (NULL == hStream)
  2184. {
  2185. ResultStream << "Can't open audio stream";
  2186. goto exitpt;
  2187. }
  2188. Stream = (PSNDSTREAM)MapViewOfFile(
  2189. hStream,
  2190. FILE_MAP_ALL_ACCESS,
  2191. 0, 0, // offset
  2192. sizeof(*Stream)
  2193. );
  2194. if (NULL == Stream)
  2195. {
  2196. ResultStream << "Can't lock audio stream memory";
  2197. goto exitpt;
  2198. }
  2199. if ( 0 != (TSSNDCAPS_ALIVE & Stream->dwSoundCaps) )
  2200. {
  2201. ResultStream << "Passed";
  2202. rv = ePassed;
  2203. }
  2204. else
  2205. {
  2206. ResultStream << "Client doesn't have audio hardware or audio redirection is not enabled on the client side";
  2207. rv = eFailed;
  2208. }
  2209. exitpt:
  2210. if ( NULL != Stream )
  2211. UnmapViewOfFile( Stream );
  2212. if ( NULL != hStream )
  2213. CloseHandle( hStream );
  2214. return rv;
  2215. }
  2216. EResult NotConsoleAudio( ostrstream &ResultStream )
  2217. {
  2218. EResult rv = eFailedToExecute;
  2219. if (NtCurrentPeb()->SessionId == 0 || IsItPTS())
  2220. {
  2221. HANDLE hConsoleAudioEvent = OpenEvent(SYNCHRONIZE, FALSE, L"Global\\WinMMConsoleAudioEvent");
  2222. if (hConsoleAudioEvent != NULL)
  2223. {
  2224. DWORD status = WaitForSingleObject(hConsoleAudioEvent, 0);
  2225. if (status == WAIT_OBJECT_0)
  2226. {
  2227. ResultStream << "Client audio settings are: Leave at remote computer";
  2228. rv = eFailed;
  2229. }
  2230. else
  2231. {
  2232. ResultStream << "Passed";
  2233. rv = ePassed;
  2234. }
  2235. CloseHandle(hConsoleAudioEvent);
  2236. }
  2237. else
  2238. {
  2239. ResultStream << "Failed to open Global\\WinMMConsoleAudioEvent";
  2240. rv = eFailedToExecute;
  2241. }
  2242. }
  2243. else
  2244. {
  2245. ResultStream << "Not running on remote console or Whistler Professional";
  2246. rv = ePassed;
  2247. }
  2248. return rv;
  2249. }
  2250. EResult CanRedirectLPT (ostrstream &ResultStream)
  2251. {
  2252. USES_CONVERSION;
  2253. ASSERT(AreWeInsideSession());
  2254. WINSTATIONCONFIG *pWSInfo = NULL;
  2255. if (GetWinstationConfiguration(&pWSInfo))
  2256. {
  2257. if (pWSInfo->User.fDisableLPT)
  2258. {
  2259. ResultStream << "Failed. LPT port Redirection is disabled either by Group Policy or TSCC settings.";
  2260. return eFailed;
  2261. }
  2262. else
  2263. {
  2264. ResultStream << "Passed";
  2265. return ePassed;
  2266. }
  2267. }
  2268. else
  2269. {
  2270. ResultStream << "Failed to retrive config data";
  2271. return eFailedToExecute;
  2272. }
  2273. }
  2274. bool CanRunAllTests()
  2275. {
  2276. return DoIHaveEnufPermissions();
  2277. }
  2278. bool CanRunGeneralInfo ()
  2279. {
  2280. return DoIHaveEnufPermissions();
  2281. }
  2282. bool CanRunCantConnect ()
  2283. {
  2284. return (CanPing() && DoIHaveEnufPermissions());
  2285. }
  2286. bool CanRunCantPrint ()
  2287. {
  2288. return AreWeInsideSession();
  2289. }
  2290. bool CanRunCantCopyPaste ()
  2291. {
  2292. return AreWeInsideSession();
  2293. }
  2294. bool CanRunFileRedirect ()
  2295. {
  2296. return AreWeInsideSession();
  2297. }
  2298. bool CanRunLptRedirect ()
  2299. {
  2300. return AreWeInsideSession();
  2301. }
  2302. bool CanRunComRedirect ()
  2303. {
  2304. return AreWeInsideSession();
  2305. }
  2306. bool CanRunAudioRedirect ()
  2307. {
  2308. return AreWeInsideSession();
  2309. }
  2310. TCHAR *WhyCantRunAllTests()
  2311. {
  2312. ASSERT(!CanRunAllTests());
  2313. if (!DoIHaveEnufPermissions())
  2314. {
  2315. return _T("You do not have sufficient permissions to run this test against target system.");
  2316. }
  2317. else
  2318. {
  2319. ASSERT(false);
  2320. return _T("WhyCantRunAllTests");
  2321. }
  2322. }
  2323. TCHAR *WhyCantRunGeneralInfo()
  2324. {
  2325. ASSERT(!CanRunGeneralInfo());
  2326. if (!DoIHaveEnufPermissions())
  2327. {
  2328. return _T("You do not have sufficient permissions to run this test against target system.");
  2329. }
  2330. else
  2331. {
  2332. ASSERT(false);
  2333. return _T("WhyCantRunGeneralInfo");
  2334. }
  2335. }
  2336. TCHAR *WhyCantRunCantConnect()
  2337. {
  2338. ASSERT(!CanRunCantConnect());
  2339. if (!CanPing())
  2340. {
  2341. return _T("Ping test Failed for target machine. Please make sure target machine is on the network");
  2342. }
  2343. if (!DoIHaveEnufPermissions())
  2344. {
  2345. return _T("You do not have sufficient permissions to run this test against target system.");
  2346. }
  2347. else
  2348. {
  2349. ASSERT(false);
  2350. return _T("WhyCantRunCantConnect");
  2351. }
  2352. }
  2353. TCHAR *WhyCantRunCantPrint()
  2354. {
  2355. ASSERT(!CanRunCantPrint());
  2356. if (!AreWeInsideSession())
  2357. {
  2358. return _T("For diagnosing this problem, you mush run these troubleshooter within the session. Plese create a remote desktop session to the target machine, and then troubleshoot");
  2359. }
  2360. else
  2361. {
  2362. ASSERT(false);
  2363. return _T("WhyCantRunCantPrint");
  2364. }
  2365. }
  2366. TCHAR *WhyCantRunCantCopyPaste()
  2367. {
  2368. ASSERT(!CanRunCantCopyPaste());
  2369. if (!AreWeInsideSession())
  2370. {
  2371. return _T("For diagnosing this problem, you mush run these troubleshooter within the session. Plese create a remote desktop session to the target machine, and then troubleshoot");
  2372. }
  2373. else
  2374. {
  2375. ASSERT(false);
  2376. return _T("WhyCantRunCantCopyPaste");
  2377. }
  2378. }
  2379. TCHAR *WhyCantRunFileRedirect()
  2380. {
  2381. ASSERT(!CanRunFileRedirect());
  2382. if (!AreWeInsideSession())
  2383. {
  2384. return _T("For diagnosing this problem, you mush run these troubleshooter within the session. Plese create a remote desktop session to the target machine, and then troubleshoot");
  2385. }
  2386. else
  2387. {
  2388. ASSERT(false);
  2389. return _T("WhyCantRunFileRedirect");
  2390. }
  2391. }
  2392. TCHAR *WhyCantRunLptRedirect()
  2393. {
  2394. ASSERT(!CanRunLptRedirect());
  2395. if (!AreWeInsideSession())
  2396. {
  2397. return _T("For diagnosing this problem, you mush run these troubleshooter within the session. Plese create a remote desktop session to the target machine, and then troubleshoot");
  2398. }
  2399. else
  2400. {
  2401. ASSERT(false);
  2402. return _T("WhyCantRunLptRedirect");
  2403. }
  2404. }
  2405. TCHAR *WhyCantRunComRedirect()
  2406. {
  2407. ASSERT(!CanRunComRedirect());
  2408. if (!AreWeInsideSession())
  2409. {
  2410. return _T("For diagnosing this problem, you mush run these troubleshooter within the session. Plese create a remote desktop session to the target machine, and then troubleshoot");
  2411. }
  2412. else
  2413. {
  2414. ASSERT(false);
  2415. return _T("WhyCantRunComRedirect");
  2416. }
  2417. }
  2418. TCHAR *WhyCantRunAudioRedirect()
  2419. {
  2420. ASSERT(!CanRunAudioRedirect());
  2421. if (!AreWeInsideSession())
  2422. {
  2423. return _T("For diagnosing this problem, you mush run these troubleshooter within the session. Plese create a remote desktop session to the target machine, and then troubleshoot");
  2424. }
  2425. else
  2426. {
  2427. ASSERT(false);
  2428. return _T("WhyCantRunAudioRedirect");
  2429. }
  2430. }