Changeset 48678 in vbox
- Timestamp:
- Sep 25, 2013 11:11:22 AM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 89300
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp
r47977 r48678 44 44 #include "../../WINNT/VBoxTray/VBoxTrayMsg.h" /* For IPC. */ 45 45 46 static uint32_t s_uGuestPropClientID = 0; 47 static uint32_t s_uIter = 0; 46 static uint32_t s_uDebugGuestPropClientID = 0; 47 static uint32_t s_uDebugIter = 0; 48 /** Whether to skip the logged-in user detection over RDP or not. 49 * See notes in this section why we might want to skip this. */ 50 static bool s_fSkipRDPDetection = false; 48 51 49 52 /******************************************************************************* … … 138 141 AssertReturn(cbName, VERR_INVALID_PARAMETER); 139 142 143 /** @todo Only do this once. Later. */ 140 144 OSVERSIONINFOEX OSInfoEx; 141 145 RT_ZERO(OSInfoEx); … … 547 551 { 548 552 VBoxServiceError("User SID=%p is not valid\n", pSessionData->Sid); 553 if (pSessionData) 554 LsaFreeReturnBuffer(pSessionData); 549 555 return 0; 550 556 } … … 741 747 pUserInfo->wszLogonDomain); 742 748 743 /* Detect RDP sessions as well. */ 744 LPTSTR pBuffer = NULL; 745 DWORD cbRet = 0; 746 int iState = -1; 747 if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, 748 pSessionData->Session, 749 WTSConnectState, 750 &pBuffer, 751 &cbRet)) 749 /** 750 * Note: On certain Windows OSes WTSQuerySessionInformation leaks memory when used 751 * under a heavy stress situation. There are hotfixes available from Microsoft. 752 * 753 * See: http://support.microsoft.com/kb/970910 754 */ 755 if (!s_fSkipRDPDetection) 752 756 { 753 if (cbRet) 754 iState = *pBuffer; 755 VBoxServiceVerbose(3, "Account User=%ls, WTSConnectState=%d (%ld)\n", 756 pUserInfo->wszUser, iState, cbRet); 757 if ( iState == WTSActive /* User logged on to WinStation. */ 758 || iState == WTSShadow /* Shadowing another WinStation. */ 759 || iState == WTSDisconnected) /* WinStation logged on without client. */ 760 { 761 /** @todo On Vista and W2K, always "old" user name are still 762 * there. Filter out the old one! */ 763 VBoxServiceVerbose(3, "Account User=%ls using TCS/RDP, state=%d \n", 764 pUserInfo->wszUser, iState); 757 /** @todo Only do this once. Later. */ 758 OSVERSIONINFOEX OSInfoEx; 759 RT_ZERO(OSInfoEx); 760 OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 761 762 /* Skip RDP detection on non-NT systems. */ 763 if ( !GetVersionEx((LPOSVERSIONINFO) &OSInfoEx) 764 || OSInfoEx.dwPlatformId != VER_PLATFORM_WIN32_NT) 765 { 766 s_fSkipRDPDetection = true; 767 } 768 /* Skip RDP detection on Windows 2000. 769 * For Windows 2000 however we don't have any hotfixes, so just skip the 770 * RDP detection in any case. */ 771 if ( OSInfoEx.dwMajorVersion == 5 772 && OSInfoEx.dwMinorVersion == 0) 773 { 774 s_fSkipRDPDetection = true; 775 } 776 777 if (s_fSkipRDPDetection) 778 VBoxServiceVerbose(0, "Detection of logged-in users via RDP is disabled\n"); 779 } 780 781 if (!s_fSkipRDPDetection) 782 { 783 /* Detect RDP sessions as well. */ 784 LPTSTR pBuffer = NULL; 785 DWORD cbRet = 0; 786 int iState = -1; 787 if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, 788 pSessionData->Session, 789 WTSConnectState, 790 &pBuffer, 791 &cbRet)) 792 { 793 if (cbRet) 794 iState = *pBuffer; 795 VBoxServiceVerbose(3, "Account User=%ls, WTSConnectState=%d (%ld)\n", 796 pUserInfo->wszUser, iState, cbRet); 797 if ( iState == WTSActive /* User logged on to WinStation. */ 798 || iState == WTSShadow /* Shadowing another WinStation. */ 799 || iState == WTSDisconnected) /* WinStation logged on without client. */ 800 { 801 /** @todo On Vista and W2K, always "old" user name are still 802 * there. Filter out the old one! */ 803 VBoxServiceVerbose(3, "Account User=%ls using TCS/RDP, state=%d \n", 804 pUserInfo->wszUser, iState); 805 fFoundUser = true; 806 } 807 if (pBuffer) 808 WTSFreeMemory(pBuffer); 809 } 810 else 811 { 812 DWORD dwLastErr = GetLastError(); 813 switch (dwLastErr) 814 { 815 /* 816 * Terminal services don't run (for example in W2K, 817 * nothing to worry about ...). ... or is on the Vista 818 * fast user switching page! 819 */ 820 case ERROR_CTX_WINSTATION_NOT_FOUND: 821 VBoxServiceVerbose(3, "No WinStation found for user=%ls\n", 822 pUserInfo->wszUser); 823 break; 824 825 default: 826 VBoxServiceVerbose(3, "Cannot query WTS connection state for user=%ls, error=%ld\n", 827 pUserInfo->wszUser, dwLastErr); 828 break; 829 } 830 765 831 fFoundUser = true; 766 832 } 767 if (pBuffer)768 WTSFreeMemory(pBuffer);769 }770 else771 {772 DWORD dwLastErr = GetLastError();773 switch (dwLastErr)774 {775 /*776 * Terminal services don't run (for example in W2K,777 * nothing to worry about ...). ... or is on the Vista778 * fast user switching page!779 */780 case ERROR_CTX_WINSTATION_NOT_FOUND:781 VBoxServiceVerbose(3, "No WinStation found for user=%ls\n",782 pUserInfo->wszUser);783 break;784 785 default:786 VBoxServiceVerbose(3, "Cannot query WTS connection state for user=%ls, error=%ld\n",787 pUserInfo->wszUser, dwLastErr);788 break;789 }790 791 fFoundUser = true;792 833 } 793 834 } … … 948 989 AssertPtrReturn(pcUsersInList, VERR_INVALID_POINTER); 949 990 950 PLUID paSessions = NULL; 951 ULONG cSessions = 0; 952 953 int rc2 = VbglR3GuestPropConnect(&s_uGuestPropClientID); 991 int rc2 = VbglR3GuestPropConnect(&s_uDebugGuestPropClientID); 954 992 AssertRC(rc2); 955 993 956 994 /* This function can report stale or orphaned interactive logon sessions 957 995 of already logged off users (especially in Windows 2000). */ 996 PLUID paSessions = NULL; 997 ULONG cSessions = 0; 958 998 NTSTATUS rcNt = LsaEnumerateLogonSessions(&cSessions, &paSessions); 959 999 if (rcNt != STATUS_SUCCESS) … … 974 1014 975 1015 default: 976 VBoxServiceError("LsaEnumerate failed with error % u\n", ulError);1016 VBoxServiceError("LsaEnumerate failed with error %RU32\n", ulError); 977 1017 break; 978 1018 } 1019 1020 if (paSessions) 1021 LsaFreeReturnBuffer(paSessions); 979 1022 980 1023 return RTErrConvertFromWin32(ulError); … … 1028 1071 char szDebugSessionPath[255]; RTStrPrintf(szDebugSessionPath, sizeof(szDebugSessionPath), "/VirtualBox/GuestInfo/Debug/LSA/Session/%RU32", 1029 1072 userSession.ulLastSession); 1030 VBoxServiceWritePropF(s_u GuestPropClientID, szDebugSessionPath,1031 "#%RU32: cSessionProcs=%RU32 (of %RU32 procs total)", s_u Iter, cCurSessionProcs, cProcs);1073 VBoxServiceWritePropF(s_uDebugGuestPropClientID, szDebugSessionPath, 1074 "#%RU32: cSessionProcs=%RU32 (of %RU32 procs total)", s_uDebugIter, cCurSessionProcs, cProcs); 1032 1075 } 1033 1076 … … 1089 1132 1090 1133 if (g_cVerbosity > 3) 1091 VBoxServiceWritePropF(s_u GuestPropClientID, "/VirtualBox/GuestInfo/Debug/LSA",1134 VBoxServiceWritePropF(s_uDebugGuestPropClientID, "/VirtualBox/GuestInfo/Debug/LSA", 1092 1135 "#%RU32: cSessions=%RU32, cProcs=%RU32, cUniqueUsers=%RU32", 1093 s_u Iter, cSessions, cProcs, cUniqueUsers);1136 s_uDebugIter, cSessions, cProcs, cUniqueUsers); 1094 1137 1095 1138 VBoxServiceVerbose(3, "Found %u unique logged-in user(s)\n", … … 1102 1145 { 1103 1146 char szDebugUserPath[255]; RTStrPrintf(szDebugUserPath, sizeof(szDebugUserPath), "/VirtualBox/GuestInfo/Debug/LSA/User/%RU32", i); 1104 VBoxServiceWritePropF(s_u GuestPropClientID, szDebugUserPath,1147 VBoxServiceWritePropF(s_uDebugGuestPropClientID, szDebugUserPath, 1105 1148 "#%RU32: szName=%ls, sessionID=%RU32, cProcs=%RU32", 1106 s_u Iter, pUserInfo[i].wszUser, pUserInfo[i].ulLastSession, pUserInfo[i].ulNumProcs);1149 s_uDebugIter, pUserInfo[i].wszUser, pUserInfo[i].ulLastSession, pUserInfo[i].ulNumProcs); 1107 1150 } 1108 1151 … … 1153 1196 VBoxServiceVMInfoWinProcessesFree(cProcs, paProcs); 1154 1197 } 1155 LsaFreeReturnBuffer(paSessions); 1156 1157 s_uIter++; 1158 VbglR3GuestPropDisconnect(s_uGuestPropClientID); 1198 if (paSessions) 1199 LsaFreeReturnBuffer(paSessions); 1200 1201 s_uDebugIter++; 1202 VbglR3GuestPropDisconnect(s_uDebugGuestPropClientID); 1159 1203 1160 1204 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.